Thursday, April 21, 2011

Creating a DLL in Visual Studio


This was another subject neglected in my formal schooling. I picked it up through trial and error, but you won’t have to as I’m about to run through an example for you.
In this example I’ll be using Visual Studio 2010 to create a dynamic link library out of a C file and use it in a managed C++ project.
For the C DLL:
Create a Win32 Project. Application type: DLL. Empty Project.
Create your C file. I called mine retnum.c.
The text of my retnum.c is very simple:
__declspec(dllexport) int retnum()
{
        return 5;
}
The __declspec(dllexport) lets the compiler know we want to use this function in a DLL.
For the C++ project.
Lets create a simple CLR Console Application project under the same solution as our C project.
Right click on your solution and go to properties, set startup project to be your C++ project. Also, go to project dependencies, on the “Project” dropdown menu select you C++ project and check off your C project.
Right click on your C++ project and go to properties. Go to Common Properties, Frameworks and References, click “add new reference”. Select your C project.
Create a header file under your C++ project. I called mine cdll.h.
The text of my cdll.h is:
extern "C"
{
   retnum();
}
The extern "C" lets our C++ program know we will be using C code.
The meat of my C++ project was in my app.cpp file. Condense as follows:
#include "stdafx.h"
#include <iostream>
#include "cdll.h"

using namespace System;
using namespace std;

int main(array<System::String ^> ^args)
{
    int i = retnum();
      Console::WriteLine(L"Your number is: "+i);
      cin.get();
    return 0;
}
So, that’s how you create a C DLL and use it in a C++ project in Visual Studio.

Project files now available on the download website.

Wednesday, April 6, 2011

Why US TV Sucks?

I’d like to start out this post with a little story. I used to watch CNN every morning to catch the news before heading off to the day’s business. One day I got up a little earlier than usual and caught the end CNN Worldwide broadcast rather than the usual CNN America broadcast. This day had been a particularly bad day in Iraq, a particularly important Golden Mosque had been bombed. CNN Worldwide was covering the attack, explaining the importance of the mosque and how the attacks would mean further setbacks to the piece process in the area.
Then the broadcast switched to CNN America. They were covering the death of Anna Nicole Smith. For the fifth day in a row. No mention of Iraq or the bombing at the mosque. That was the last time I watched CNN.
I understand why they do it. They need to be entertaining because, while informative is their job description, entertaining pays the bills. Entertainment brings in viewers, those viewers show up on ratings, advertisers use those ratings to justify the price of their advertisements. But, do you know how the ratings system works?
The principle rating system in the US is done by Nielsen Media Research. Many people assume that whenever you watch a program, Nielsen (if people actually know their name) or some other company records this information, aggregates it, and then reports this information to the advertisers. People may believe this because it seems obvious with the extensive use of digital satellite or cable boxes. But I’ve seen people who believed that ratings could be collected over analog as well.
However, this is not how Neilson collects their ratings.
Neilson will call up, at random, households and ask if they would be interested in participating in their ratings service. These families receive a box and the demographic information for each family member is added to the box. In total 25,000 families are used in the study. There are 114,500,000 households in the US with TVs. That means that 0.03%, the 0.03% that picked up that call and agreed to be tracked, of US household have direct control over what shows stay and go on US TV.
And boy does that 0.03% love their cheesy sitcoms, crime dramas, and reality shows. And their love for those perticuar shows are the reason you see wresting on SyFy or the Jersey Shore on MTV or one of the other hundreds of networks become just another Spike TV. It’s called network decay.
I should mention, that some good came out of my ban on CNN, I began getting my news from BBC America. And because of that, I discovered Top Gear. Even though I’m not that into car, I love Top Gear. In a way it’s similar to Giant Bomb. You watch it for the chemistry, to see 3 guys hang out just hang out. You would watch it even if the show was about kitchenware.
I guess it’s a bit unfair to say only US TV sucks. Perhaps, other countries have bad TV. Perhaps, all TV is bad.

Friday, April 1, 2011

Download Site Ready

Really short announcement. Been kind of busy this week, but I managed to get the download site up and running. Added the sample makefile I did a few days ago, haven’t tested it though. Will probably make the site a bit cleaner in the future.
Download site is located here.