Click here to Skip to main content
12,814,994 members (37,022 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ 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

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

Solution 2

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

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 19 Jul 2012
Copyright © CodeProject, 1999-2017
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