Click here to Skip to main content
11,629,614 members (72,564 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC9.0 DLL
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.
    	}
Posted 19-Jul-12 1:40am
vikky08902
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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".
  Permalink  

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

  Print Answers RSS


Advertise | Privacy | Mobile
Web03 | 2.8.150723.1 | Last Updated 19 Jul 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100