0
votes

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.
}
2
what happens when you change var = (LPVAR)GetProcAddress(hDLL, "Ver_C"); to var = new (LPVAR)GetProcAddress(hDLL, "Ver_C");huseyin tugrul buyukisik
this error occur..."cannot convert from 'CProductionTestDlg::LPVAR *' to 'CProductionTestDlg::LPVAR'"Jitendra
then put a * into that (LPVAR(probably here))huseyin tugrul buyukisik
No this is not working:(Jitendra
ok. forget all those. just change the declaration type to LPVAR*huseyin tugrul buyukisik

2 Answers

0
votes

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)

0
votes

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 );
}