Dynamic Linking C++ DLL ... What am I doing wrong?
<p>I've been trying to create a DLL and link the DLL to my program but every time I try my program can't find the function. The DLL loads fine but the function cant be found.</p>

<p>Program:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;windows.h&gt;
using namespace std;

typedef void (*HelloPtr)();

int main() { 
    HelloPtr hello;
    HINSTANCE hDll = LoadLibrary("dll.dll");
    if(hDll)
    {
        hello = (HelloPtr)GetProcAddress(hDll, "hello");
        if(hello) {
            hello();
        } else {
            // Error code here
        }
    }
    return 0;   
}
</code></pre>

<p>dllmain.cpp</p>

<pre><code>#include "dll.h"
#include &lt;windows.h&gt;

DLLIMPORT void hello()
{
   MessageBox(NULL, "Hey", "", MB_OK);          
}

DllClass::DllClass()
{

}

DllClass::~DllClass ()
{

}


BOOL APIENTRY DllMain (HINSTANCE hInst     /* Library instance handle. */ ,
                       DWORD reason        /* Reason this function is being called. */ ,
                       LPVOID reserved     /* Not used. */ )
{
    switch (reason)
    {
        case DLL_PROCESS_ATTACH:
        break;

        case DLL_PROCESS_DETACH:
        break;

        case DLL_THREAD_ATTACH:
        break;

        case DLL_THREAD_DETACH:
        break;
    }

    /* Returns TRUE on success, FALSE on failure */
    return TRUE;
}
</code></pre>

<p>dll.h</p>

<pre><code>#ifndef _DLL_H_
#define _DLL_H_

#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport) void hello(void)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllexport) void hello(void)
#endif /* Not BUILDING_DLL */

class DLLIMPORT DllClass
{
    public:
    DllClass();
    virtual ~DllClass(void);

    // Says hello world
    DLLImport void hello(void);

    private:

};


#endif /* _DLL_H_ */
</code></pre>

<p>I'd like to know what I'm doing wrong so I can document it and learn.</p>

<p>Thanks</p>
