Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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

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



In .cpp file

C++
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.
    	}
Posted

The docs for GetProcAddress[^] say it returns NULL if if fails

You're getting a NULL back (i worked that out from the exception) and you've got zero error handling in there
 
Share this answer
 
Quote:
var = (LPVAR)GetProcAddress(hDLL, "Ver_C");


The "Ver_C" should match the name of your exported function exactly. Make sure you have a function named that, if you don't, that's your problem. If you do have a function named that, make sure it was a C-style export or else the name probably contains "name mangling".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900