Looking for some help, problems with C++ Dlls (Using Visual Studio C++ 6.0)

D

Dave

Hi everyone. Okay, I'm trying to dynamically link some dlls and I'm
having some problems. I originally had a project that seems to work,
but for the life of me I can't repeat the results.

I used app wizard to create a simple Win32 Dynamic Linked library. the
code is as follows:


#include "stdafx.h"
#include "stdio.h"

int i = 0;

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}

void _stdcall InitDll(){
i = 1;
}



I build that and get 'TestDll.dll'

The program I use to open this dll looks like this:


#include "stdafx.h"
#include <windows.h>


typedef void(__stdcall *InitDllOperation)();


int main(int argc, char* argv[])
{

InitDllOperation initDll;

HINSTANCE dllLib = LoadLibrary("TestDll.dll");

if( dllLib == NULL )
{
printf( "Unable to load library\n");
return 1;
}
else
{
printf( "loaded library successfully\n");
}

initDll =
(InitDllOperation)GetProcAddress((HINSTANCE)dllLib,"InitDll");

if( initDll == NULL )
{
printf( "initDll failed to load\n");
return 1;
}
else
{
printf( "init Success\n");
}

return 0;
}


Every time the library loads successfully, but the 'initDll' object is
ALWAYS Null. The return from GetProcAddress seems to always come up
null. Any suggestions?

Thanks
 
M

Markus Svilans

Hi everyone. Okay, I'm trying to dynamically link some dlls and I'm
having some problems. I originally had a project that seems to work,
but for the life of me I can't repeat the results.

[ snip ]
}Every time the library loads successfully, but the 'initDll' object is
ALWAYS Null. The return from GetProcAddress seems to always come up
null. Any suggestions?

Hello Dave,

Your question is off topic here, but you can check two things:

1. Exporting functions from DLLs requires using __declspec(export)
2. Name mangling needs to be disabled on exported functions. Mangled
names may not be what you expect, so GetProcAddress may not find the
function you want.

Search for some sample code on Google. There are plenty of good
examples available.

But again, this question is off topic here. :)

Regards,
Markus.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top