0

I want to call my vc++ dll in my vc++ code. but the error occur that Unhandled exception at 0x00000000 in .exe: 0xC0000005: Access violation reading location 0x00000000.

after last line.I have call vc++ dll by ordinal no.

In .h file

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

In .cpp file

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


if( hDLL == NULL )
    AfxMessageBox("Could not load the DLL");

/*int ordinal = 2;
HMODULE  dll = LoadLibrary("Prod.dll");
FARPROC fn = GetProcAddress(dll, MAKEINTRESOURCE(ordinal));*/ //how to proceed after this.

else
{
    var = (LPVAR)GetProcAddress(hDLL, "Ver_C");
    char *ch,a;
    ch = (char*)malloc(100*sizeof(char));

    a = 'z'; 
    int ans = var(ch,&a); //Unhandle exception after that.
}
Rob
  • 4,927
  • 12
  • 49
  • 54
jiten
  • 5,128
  • 4
  • 44
  • 73

2 Answers2

0

Looks like your var function pointer is NULL. It means that Ver_C is not exported.

You can use dumpbin.exe /exports Prod.dll to check what functions are exported (and their names)

qehgt
  • 2,972
  • 1
  • 22
  • 36
0

Actually the problem were freelibrary after free it ans has currect value.

else
   {
    var =(LPVAR)GetProcAddress(hDLL, MAKEINTRESOURCE(2));
    char *ch,a;
    ch = (char*)malloc(100*sizeof(char));

    a = 'z';
    int ans;
     ans = var(ch,&a);
     if ( hDLL != NULL )
             FreeLibrary( hDLL );
}
jiten
  • 5,128
  • 4
  • 44
  • 73