   DLL loading problems.. GetProcAddress
  I''m doing a dll on my pocketpc and it fails when I try to get a function pointer from it.I have this in the dll code:__declspec (dllexport) void InitFunc (void);void InitFunc (void){...}And this is how I load the dll in the main program:HINSTANCE hDll;FARPROC dllInitFunc;void LoadLib (void){  DWORD err;  hDll=LoadLibrary(L"mylib.dll");  if (hDll==NULL){    MessageBox(hWnd,L"Failed to load dll",L"Error",MB_OK);    return;  }  dllInitFunc=GetProcAddress(hVibradll,L"InitFunc");  if (dllInitFunc==NULL){    err=GetLastError();    MessageBox(hWnd,L"Failed to get proc address",L"Error",MB_OK);  }}dllInitFunc becomes NULL and err is 87, ERROR_INVALID_PARAMETER.What am I doing wrong? 
quote:hDll=LoadLibrary(L"mylib.dll");dllInitFunc=GetProcAddress(hVibradll,L"InitFunc");Perhaps the fact that you''re not passing in the correct DLL handle? "Sneftel is correct, if rather vulgar." --Flarelocke ;  Also, with name mangling, the name of the function stored in the export table of the DLL may not be "InitFunc". You should check a export dump of the DLL to make sure you''re using the right name. ;  Oh, thats a typo.. I have the right handle...Hmm, I''ll check the function name but I think its correct. ;  FARPROC is a typedef to a function pointer that returns an int.  Your function in your DLL is void.typedef void (*MY_PFN)(void);MY_PFN dllInitFunc;that should work... also, just for some cover yer a$$, not a bad idea to cast the GetProcAddress...dllInitFunc = (MY_PFN)GetProcAddress(hDll, "InitFunc"); [edited by - stonicus on February 12, 2004 3:48:31 PM];quote:Original post by AndersO  dllInitFunc=GetProcAddress(hVibradll,L"InitFunc");What am I doing wrong?try replacing that line with:dllInitFunc=GetProcAddressA(hDll,"InitFunc");I''m guessing that the unicode vs ascii stuff is the problem. ;  FWIW: You can persuade a function to not mangle it''s name in the original file by inserting a prototype as an ''extern "C" '' in the same cpp file as it is (technically it uses the c naming conventions), ie// somecppfile.cpp - contains InitFunc....extern "C" void InitFunc();...// somewhere in the same filevoid InitFunc(void){    // do something useful here} ;  Ah yea!.. That was it, extern "C". Thanks! Guess it was name mangling after all.And thanks all for your suggestions! 