在vc ++代码中调用vc ++ dll时出现未处理的异常 [英] Unhandled exception when call vc++ dll in vc++ code

查看:70
本文介绍了在vc ++代码中调用vc ++ dll时出现未处理的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用我的vc ++代码调用我的vc ++ dll.
但是发生错误,原因是 .exe中0x00000000处未处理的异常:0xC0000005:访问冲突读取位置0x00000000.

最后一行之后.我已按序号调用vc ++ dll.

在.h文件中

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




在.cpp文件中




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

推荐答案

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


报价:

var =(LPVAR)GetProcAddress(hDLL,"Ver_C");

var = (LPVAR)GetProcAddress(hDLL, "Ver_C");



"Ver_C"应该与您导出函数的名称完全匹配.确保您有一个名为的函数,如果没有,那就是您的问题.如果您确实有一个名为that的函数,请确保它是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".


这篇关于在vc ++代码中调用vc ++ dll时出现未处理的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆