0

How to call vc++ dll in vc++.

in .h file

typedef int (*LPVAR)(char * ptr_f, char *CC);
HINSTANCE hDLL;

in .cpp file

hDLL = NULL;
LPVAR var;
hDLL = LoadLibrary("Pro.dll");


if( hDLL == NULL )
    AfxMessageBox("Could not load the DLL");
else
{
    var = (LPVAR)GetProcAddress(hDLL, "#2"); //2 is ordinal no
    char *ch,*a;
    ch = (char*)malloc(100*sizeof(char));
    a = (char*)malloc(10*sizeof(char));
    int c = var(ch,a);
}
jiten
  • 5,128
  • 4
  • 44
  • 73

1 Answers1

1

Check that var is not NULL after calling GetProcAddress.

You may have more success using MAKEINTRESOURCE, like this:

var = (LPVAR)GetProcAddress(hDLL, MAKEINTRESOURCE(2));

Remember to call free for the pointers returned by malloc, and call FreeLibrary when you have finished with hDLL.

Community
  • 1
  • 1
PhilMY
  • 2,621
  • 21
  • 29
  • Yes after that var is not null but after calling var, int c not update – jiten Jul 19 '12 at 12:13
  • Have you checked the [calling convention](http://msdn.microsoft.com/en-us/library/984x0h58.aspx) of the DLL? You might need to add one of those keywords to your `typedef`. – PhilMY Jul 19 '12 at 12:25