VC++、DLL、虚函数、调用约定

关于“VC++、DLL、虚函数、调用约定”的一个问题折腾我很久了,希望CSDN的朋友可以助我解决问题。

DLL里,接口类的虚函数(非纯虚函数),应该怎样调用约定?


背景描述:
一个DLL工程A(接口),有个接口类AI,里面全是纯虚函数。
一个EXE工程B(平台),有个成员变量mc类型是类AI。
一个DLL工程C(游戏),有个类是类AI的子类,即实现类,对类AI的所有接口(纯虚函数)进行了实现。

原理是:
平台只有一个在跑,而游戏是N个,工程B(平台)的mc被赋值成工程C(游戏)的对象,通过工程A的接口,mc可以调用工程C(游戏)里的函数(接口的实现)。

问题:
我在开发一个新游戏时,发现工程A(接口)类AI的接口不够用,想新增一个接口,于是加入了一个”虚函数“,注意不是“纯虚函数”,为的是不影响之前所有已有的游戏(不然之前的游戏不作任何改动而编译 会报error C2259: 不能实例化抽象类),即之前的游戏不用实现这个接口,修改工程B(平台)调用这个函数时是工程A(接口)新增的接口,若游戏实现这个接口,就调用游戏里的实现函数;若游戏没有定义这个接口(之前的游戏),则调用工程A(接口)类AI里的虚函数(里面只有一句调试打印)。

但发现,有的游戏是正常的,有的游戏不正常。不正常的游戏,调试工程B(平台)在调用新接口时提示:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

百度了一下,很多人说是调名约定的问题。
工程A、工程B、所有的游戏工程C,工程选项里都是 __cdecl (/Gd)。

于是我在工程A、工程C里下面几种尝试:
virtual void OnEventABC(int a, bool b); //没写调用约定,有的游戏正常,有的游戏出错
virtual void __stdcall OnEventABC(int a, bool b); //所有的游戏都出错
virtual void __cdecl OnEventABC(int a, bool b); //所有的游戏都出错
virtual void WINAPI OnEventABC(int a, bool b); //所有的游戏都出错


请问大家,怎么解决这个问题,是调名约定的问题,还是其它什么问题?

3个回答

问题已解决,谢谢大家的无语让我自己解决了。

你没有传this指针,导致堆栈不平衡。

请问工程A、C如何写,工程B里调用如何写?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
VC++、DLL、虚函数、调用约定
n关于“VC++、DLL、虚函数、调用约定”的一个问题折腾我很久了,希望CSDN的朋友可以助我解决问题。nnDLL里,接口类的虚函数(非纯虚函数),应该怎样调用约定?nn---------------------------------------------------nn背景描述:n一个DLL工程A(接口),有个接口类AI,里面全是纯虚函数。n一个EXE工程B(平台),有个成员变量mc类型是类AI。n一个DLL工程C(游戏),有个类是类AI的子类,即实现类,对类AI的所有接口(纯虚函数)进行了实现。nn原理是:n平台只有一个在跑,而游戏是N个,工程B(平台)的mc被赋值成工程C(游戏)的对象,通过工程A的接口,mc可以调用工程C(游戏)里的函数(接口的实现)。nn问题:n我在开发一个新游戏时,发现工程A(接口)类AI的接口不够用,想新增一个接口,于是加入了一个”虚函数“,注意不是“纯虚函数”,为的是不影响之前所有已有的游戏(不然之前的游戏不作任何改动而编译 会报error C2259: 不能实例化抽象类),即之前的游戏不用实现这个接口,修改工程B(平台)调用这个函数时是工程A(接口)新增的接口,若游戏实现这个接口,就调用游戏里的实现函数;若游戏没有定义这个接口(之前的游戏),则调用工程A(接口)类AI里的虚函数(里面只有一句调试打印)。nn但发现,有的游戏是正常的,有的游戏不正常。不正常的游戏,调试工程B(平台)在调用新接口时提示:nRun-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.nn百度了一下,很多人说是调名约定的问题。n工程A、工程B、所有的游戏工程C,工程选项里都是 __cdecl (/Gd)。nn于是我在工程A、工程C里下面几种尝试:nvirtual void OnEventABC(int a, bool b); //没写调用约定,有的游戏正常,有的游戏出错nvirtual void __stdcall OnEventABC(int a, bool b); //所有的游戏都出错nvirtual void __cdecl OnEventABC(int a, bool b); //所有的游戏都出错nvirtual void WINAPI OnEventABC(int a, bool b); //所有的游戏都出错nn---------------------------------------------------nn请问大家,怎么解决这个问题,是调名约定的问题,还是其它什么问题?n
vc DLL调用约定错误
实时错误49,DLL调用约定错误:rnrnvc原型:rntypedef void (CALLBACK * CONNECT_STATUS_CALLBACK)(int handle, int channel, unsigned char biCmd, int nResult, BYTE * pRetData, void* pContext);rnrnvoid WINAPI ConnectStatusCallBack(int handle,int channel,CONNECT_STATUS_CALLBACK connect_status_callback,void* pContext);rnrnrnvb声明:rnSub ConnectingProc(ByVal handle As Long, ByVal Channel As Long, ByVal biCmd As Byte, ByVal nResult As Long, ByVal pRetData As Long, ByVal pContext As Long)rnrnDeclare Function ConnectStatusCallBack Lib "Media.dll" (ByVal handle As Long, ByVal Channel As Long, ByVal pconnect_status_callback As Long, ByRef pContext As ContextInfo)
vb调用vc dll ,"DLL 调用约定错误"
被调用的VC DLL,出错的函数的函数原型为:rnint __stdcall GetRecvFrame(int iComNo,int *pInfoType, int *pRespType,unsigned char *pRecvBuff, int *pLen,int nWaitTime = 2000);rnrnVB里的函数声明:rnPrivate Declare Function GetRecvFrame Lib "DsrcApi.dll" (ByVal iComNo As long, ByRef pInfoType As long, ByRef pRespType As long, ByRef pRecvBuff As String, ByRef pLen As long, Optional ByRef nWaitTime As long= 2000)rnrnVB里面的函数调用为:rn Dim value As longrn Dim infoType As longrn Dim respType As longrn Dim recvBuff As Stringrn Dim buffLen As longrnrn recvBuff = String(2000, 0)rnrn [color=#FF0000] value = GetRecvFrame(com, infoType, respType, recvBuff, buffLen)[/color]rnrn但是VB里面运行到红色那一行的时候就报错!!错误为“DLL 调用约定错误”rnrn请指教
DLL调用约定错误
为什么我在VC里写的DLL函数不带形参就能被VB调用,rn带了一个int形参,VB调用时就会出现“DLL调用约定错误“呢?
dll导出函数调用约定
__declspec(dllexport) int foo(int a, int b);rnrn头文件中这种声明方式默认的参数调用约定是什么? __cdecl还是__stdcall?rnrn如果要__stdcall一定要__declspec(dllexport) int __stdcall foo(int a, int b)吗?
dll调用约定错误?
我运行,提示:实时错误49,dll调用约定错误,这是什么原因啊rnvb:rn声明:Public Declare Function togray Lib "togray" (ByVal hdc As Long, ByVal w As Long, ByVal h As Long)rnrn调用:togray Picture1.hdc, picwidtht, picheightrnrnvc:rnextern "C" void _stdcall togray(HDC hdc,int w,int h)
求助:dll调用约定错误
我运行,提示:实时错误49,dll调用约定错误,这是什么原因啊rnvb:rn声明:Public Declare Function togray Lib "togray" (ByVal hdc As Long, ByVal w As Long, ByVal h As Long)rnrn调用:togray Picture1.hdc, picwidth, picheightrnrnvc:rnextern "C" void _stdcall togray(HDC hdc,int w,int h)rn
dll调用约定问题
1.有没有办法知道别人编写的动态库中的函数声明是用的_stdcall还是_cdecl.rn cb调别人的动态库,发现对调用的函数用_stdcall声明,返回时地址异常,用_cdecl声明,没问题。估计是双方声明的调用约定方式不同。单本人没法拿到别人的动态库原码,有什么办法可在没有动态库原吗的情况下,知道动态库中函数声明的调用约定是什么?rnrnrn2.cb中把GetProcAddress取回的用farproc转换,发现调用别人的动态库,没问题,奇怪我没有声明是_stdcall还是_cdecl,他按什么调用约定的方式调用动态库中的函数呢?
VB调用VC DLL出现DLL 的调用约定错误(49),怎么办?
使用静态MFC DLL(第一选项) rnrnDLL函数 rnextern "C" void __declspec(dllexport) __stdcall Func() rnrn rn rnrnVB调用声明 rnDeclare Function Func Lib "FuncDLL" () rnrnVB调用 rnPrivate Sub Command3_Click() rn Call Func rnEnd Sub rnrn出现“DLL 的调用约定错误(错误 49)” 为什么? rnrn49: rn传送给动态链接库 (DLL)的参数必须符合例程的需要。调用约定要检查个数、类型、参数的顺序等。 rn
VC做的dll在VB中调用,显示“DLL调用约定错误”
我用AppWizard(dll)做的dll,然后加入:rnint ModulBasicCheck(WORD ModuleNo,ULONG DogPassword,BYTE DogCascade)rnrn....rnrn.def中rnModulBasicCheck @1rn编译成功后,在vc中调用没有问题,但在vb中不行rnvb中的代码:rnPrivate Declare Function ModulBasicCheck Lib "dllapi.dll" _rn(mid As Integer, pwd As Long, csa As String) As BooleanrnPrivate Sub Form_Load()rnDim m1 As IntegerrnDim p1 As LongrnDim s1 As Stringrnm1 = 1rnp1 = 0rns1 = "0"rnMsgBox ModulBasicCheck(m1, p1, s1)rnEnd Subrnrnrn
带调用约定的虚函数返回数组引用
//纯虚基类 virtual char (& __cdecl Fun())[32] = 0 ; //子类实现覆盖 virtual char (& __cdecl Fun()) [32]{ return m_sz; } VS2012编译通过
跟dll 调用约定有关的问题
我在vc里用__stdcall调用约定做好dll,其它地方调用该dll时,dll中的函数名都已改变(不管加不加extern "C",加跟不加只是导出函数名略有不同,但都不是原名),但我想在调用时仍然用原函数名(在vc里用__cdecl调用约定时不存在此问题),请问怎么办?实在def文件里处理?还是?请帮忙。
DLL中调用约定和名称修饰
写了一篇关于DLL中调用约定和名称修饰的文章,其中还有很多内容不确定~请大家指教~谢谢~文档中心中的链接:rnhttp://www.csdn.net/Develop/read_article.asp?id=25141rnhttp://www.csdn.net/develop/Read_Article.asp?Id=25142rnhttp://www.csdn.net/develop/Read_Article.asp?Id=25143rn=============================rnDLL中调用约定和名称修饰rnrn调用约定(Calling Convention)是指在程序设计语言中为了实现函数调用而建立的一种协议。这种协议规定了该语言的函数中的参数传送方式、参数是否可变和由谁来处理堆栈等问题。不同的语言定义了不同的调用约定。rnrn在C++中,为了允许操作符重载和函数重载,C++编译器往往按照某种规则改写每一个入口点的符号名,以便允许同一个名字(具有不同的参数类型或者是不同的作用域)有多个用法,而不会打破现有的基于C的链接器。这项技术通常被称为名称改编(Name Mangling)或者名称修饰(Name Decoration)。许多C++编译器厂商选择了自己的名称修饰方案。rnrn因此,为了使其它语言编写的模块(如Visual Basic应用程序、Pascal或Fortran的应用程序等)可以调用C/C++编写的DLL的函数,必须使用正确的调用约定来导出函数,并且不要让编译器对要导出的函数进行任何名称修饰。rn1.调用约定(Calling Convention)rn调用约定用来处理决定函数参数传送时入栈和出栈的顺序(由调用者还是被调用者把参数弹出栈),以及编译器用来识别函数名称的名称修饰约定等问题。在Microsoft VC++ 6.0中定义了下面几种调用约定,我们将结合汇编语言来一一分析它们:rn1、__cdeclrn__cdecl是C/C++和MFC程序默认使用的调用约定,也可以在函数声明时加上__cdecl关键字来手工指定。采用__cdecl约定时,函数参数按照从右到左的顺序入栈,并且由调用函数者把参数弹出栈以清理堆栈。因此,实现可变参数的函数只能使用该调用约定。由于每一个使用__cdecl约定的函数都要包含清理堆栈的代码,所以产生的可执行文件大小会比较大。__cdecl可以写成_cdecl。rnrn下面将通过一个具体实例来分析__cdecl约定:rnrn在VC++中新建一个Win32 Console工程,命名为cdecl。其代码如下:rnrnint __cdecl Add(int a, int b); //函数声明rnrnvoid main()rnrn Add(1,2); //函数调用rnrnrnint __cdecl Add(int a, int b) //函数实现rnrn return (a + b);rnrnrn函数调用处反汇编代码如下:rnrn;Add(1,2);rnpush 2 ;参数从右到左入栈,先压入2rnpush 1 ;压入1rncall @ILT+0(Add) (00401005) ;调用函数实现rnadd esp,8 ;由函数调用清栈rn2、__stdcallrn__stdcall调用约定用于调用Win32 API函数。采用__stdcal约定时,函数参数按照从右到左的顺序入栈,被调用的函数在返回前清理传送参数的栈,函数参数个数固定。由于函数体本身知道传进来的参数个数,因此被调用的函数可以在返回前用一条ret n指令直接清理传递参数的堆栈。__stdcall可以写成_stdcall。rnrn还是那个例子,将__cdecl约定换成__stdcall:rnrnint __stdcall Add(int a, int b)rnrnreturn (a + b);rnrnrn函数调用处反汇编代码:rn rn ; Add(1,2);rnpush 2 ;参数从右到左入栈,先压入2rnpush 1 ;压入1rncall @ILT+10(Add) (0040100f) ;调用函数实现rnrn函数实现部分的反汇编代码:rnrn;int __stdcall Add(int a, int b)rnpush ebprnmov ebp,esprnsub esp,40hrnpush ebxrnpush esirnpush edirnlea edi,[ebp-40h]rnmov ecx,10hrnmov eax,0CCCCCCCChrnrep stos dword ptr [edi]rn;return (a + b);rnmov eax,dword ptr [ebp+8]rnadd eax,dword ptr [ebp+0Ch]rnpop edirnpop esirnpop ebxrnmov esp,ebprnpop ebprnret 8 ;清栈rn3、__fastcallrn__fastcall约定用于对性能要求非常高的场合。__fastcall约定将函数的从左边开始的两个大小不大于4个字节(DWORD)的参数分别放在ECX和EDX寄存器,其余的参数仍旧自右向左压栈传送,被调用的函数在返回前清理传送参数的堆栈。__fastcall可以写成_fastcall。rnrn依旧是相类似的例子,此时函数调用约定为__fastcall,函数参数个数增加2个:rnrnint __fastcall Add(int a, double b, int c, int d)rnrnreturn (a + b + c + d);rnrnrn函数调用部分的汇编代码:rnrn;Add(1, 2, 3, 4);rnpush 4 ;后两个参数从右到左入栈,先压入4rnmov edx,3 ;将int类型的3放入edxrnpush 40000000h ;压入double类型的2rnpush 0rnmov ecx,1 ;将int类型的1放入ecxrncall @ILT+0(Add) (00401005) ;调用函数实现rnrn函数实现部分的反汇编代码:rn rn; int __fastcall Add(int a, double b, int c, int d)rnpush ebprnmov ebp,esprnsub esp,48hrnpush ebxrnpush esirnpush edirnpush ecxrnlea edi,[ebp-48h]rnmov ecx,12hrnmov eax,0CCCCCCCChrnrep stos dword ptr [edi]rnpop ecxrnmov dword ptr [ebp-8],edxrnmov dword ptr [ebp-4],ecxrn;return (a + b + c + d);rnfild dword ptr [ebp-4]rnfadd qword ptr [ebp+8]rnfiadd dword ptr [ebp-8]rnfiadd dword ptr [ebp+10h]rncall __ftol (004011b8)rnpop edirnpop esirnpop ebxrnmov esp,ebprnpop ebprnret 0Ch ;清栈rnrn关键字__cdecl、__stdcall和__fastcall可以直接加在要输出的函数前,也可以在编译环境的Setting...->C/C++->Code Generation项选择。它们对应的命令行参数分别为/Gd、/Gz和/Gr。缺省状态为/Gd,即__cdecl。当加在输出函数前的关键字与编译环境中的选择不同时,直接加在输出函数前的关键字有效。rn4、thiscallrnthiscall调用约定是C++中的非静态类成员函数的默认调用约定。thiscall只能被编译器使用,没有相应的关键字,因此不能被程序员指定。采用thiscall约定时,函数参数按照从右到左的顺序入栈,被调用的函数在返回前清理传送参数的栈,只是另外通过ECX寄存器传送一个额外的参数:this指针。rnrn这次的例子中将定义一个类,并在类中定义一个成员函数,代码如下:rnrnclass CSumrn rnpublic:rnint Add(int a, int b)rnrnreturn (a + b);rnrn;rnrnvoid main()rn rn CSum sum;rn sum.Add(1, 2);rnrnrn函数调用部分汇编代码:rnrn;CSum sum;rn ;sum.Add(1, 2);rn push 2 ;参数从右到左入栈,先压入2rn push 1 ;压入1rn lea ecx,[ebp-4] ;ecx存放了this指针rncall @ILT+5(CSum::Add) (0040100a) ;调用函数实现rnrn函数实现部分汇编代码:rnrn;int Add(int a, int b)rn push ebprnmov ebp,esprnsub esp,44h ;多用了一个4bytes的空间用于存放this指针rnpush ebxrnpush esirnpush edirnpush ecxrnlea edi,[ebp-44h]rnmov ecx,11hrnmov eax,0CCCCCCCChrnrep stos dword ptr [edi]rnpop ecxrnmov dword ptr [ebp-4],ecxrn;return (a + b);rnmov eax,dword ptr [ebp+8]rnadd eax,dword ptr [ebp+0Ch]rnpop edirnpop esirnpop ebxrnmov esp,ebprnpop ebprnret 8 ;清栈rn5、naked属性rn采用上面所述的四种调用约定的函数在进入函数时,编译器会产生代码来保存ESI、EDI、EBX、EBP寄存器中的值,退出函数时则产生代码恢复这些寄存器的内容。对于定义了naked属性的函数,编译器不会自动产生这样的代码,需要你手工使用内嵌汇编来控制函数实现中的堆栈管理。由于naked属性并不是类型修饰符,故必须和__declspec共同使用。下面的这段代码定义了一个使用了naked属性的函数及其实现:rnrn__declspec ( naked ) func()rnrnint i;rn int j;rn rn_asmrnrnpush ebprn mov ebp, esprn sub esp, __LOCAL_SIZErnrn rn _asmrn rnmov esp, ebprn pop ebprn retrn rnrnrnnaked属性与本节关系不大,具体请参考MSDN。rn6、WINAPIrn还有一个值得一提的是WINAPI宏,它可以被翻译成适当的调用约定以供函数使用。该宏定义于windef.h之中。下面是在windef.h中的部分内容:rnrn#define CDECL _cdeclrn#define WINAPI CDECLrn#define CALLBACK __stdcallrn#define WINAPI __stdcallrn#define APIENTRY WINAPIrnrn 由此可见,WINAPI、CALLBACK、APIENTRY等宏的作用。
求解:提示DLL调用约定错误
rnint w;rnint h;rnunsigned char *ByteBuffer1;rnunsigned char *ByteBuffer2;rnlen=ProcessBuf(ByteBuffer1,ByteBuffer2,w,h);rnC++中没问题rn-----------------------------------------------------------rnrn如在VB中调用此DLLrnDeclare Function ProcessBuf Lib "Test.DLL" (ByteBuffer1 as any,ByteBuffer2 as any,byval w as long,byval h as long) as longrndim buf1(1000) as byte,buf2(1000) as byterndim w as long,h as longrndim rlen as longrn...rn..rnrlen=ProcessBuf(buf1(0),buf2(0),w,h)rnrn提示DLL调用约定错误!rnrnrlen=ProcessBuf(varptr(buf1(0)),varptr(buf2(0)),w,h)rn一样!rnrn是哪里出了错??rn
DLL问题?“DLL 调用约定错误”提示。
rn函数原型:rnrnBOOL _declspec(dllimport) SQLSCMLocalServiceStateW(LPWSTR lpszSvc,LPDWORD pdwErr);rn rnvb:rnpublic declare function SQLSCMLocalServiceState lib“....\w95scm.dll”rnalias ) SQLSCMLocalServiceStateW(byval lpszsev as string, byval pdwerr as rnlong ) as boleanrnrn error:?“DLL 调用约定错误”
怎样调用约定为CDECL的DLL?
说要调用者自己清Stack, How to do it ?
VB的DLL调用怎么“DLL调用约定错误”
"PrinterUsb.dll"里的数据类型及函数如下:rnconst int DEVNUM = 10;rnconst int PATHLEN = 200;rnrntypedef structrnrn char strDevPath[PATHLEN];rnDEVPATH;rnrntypedef structrnrn DEVPATH DevPath[DEVNUM];rn int DevNum;rnDEVINFO;rnrnint GetDevicePath(DEVINFO&);rnbool Open(int PortNum);rnbool Write(char *pBuf,DWORD nNumberOfBytesToWrite,DWORD &NumberOfBytesWritten);rnvoid Close();rnrnrn我在USB里调用DLL,作如下声明:rnrnrnPublic Const DevNum = 10rnPublic Const PATHLEN = 200rnPublic Type DEVPATHrn strDevPath(0 To PATHLEN) As StringrnEnd TypernrnPublic Type DEVINFOrn iDevPath(0 To DevNum) As DEVPATHrn DevNum As IntegerrnEnd TypernrnPublic Declare Function GetDevicePath _rn Lib "PrinterUsb.dll" _rn (ByRef sDevInfo As DEVINFO) _rnAs LongrnrnPublic Declare Function OpenUSB _rn Lib "PrinterUsb.dll" Alias "Open" _rn (ByVal PortNum As Integer) _rnAs BooleanrnrnPublic Declare Function WriteUSB _rn Lib "PrinterUsb.dll" Alias "Write" _rn (ByVal pBuf As String, _rn ByVal nNumberOfBytesToWrite As Long, _rn ByVal nNumberOfBytesWritten As Long) _rnAs BooleanrnrnPublic Declare Sub CloseUSB _rn Lib "PrinterUsb.dll" Alias "Close" ()rnrnrn程序如下:rnPrivate Sub cmdUSBTest_Click()rn Dim MyDevInfo As DEVINFOrn Dim ESC As String: ESC = Chr(27)rn Dim strCmd As Stringrn Dim nNumberOfBytesToWrite As Long: nNumberOfBytesToWrite = 0rn Dim nNumberOfBytesWritten As Long: nNumberOfBytesWritten = 10rn rn strCmd = "hello"rn rn rn GetDevicePath MyDevInforn If MyDevInfo.DevNum = 0 Thenrn MsgBox "未检测到USB设备!"rn Endrn End Ifrn rn If OpenUSB(0) = False Thenrn MsgBox "打开USB设备失败!"rn Endrn End Ifrn rn WriteUSB strCmd, nNumberOfBytesToWrite, nNumberOfBytesWrittenrn rn CloseUSBrn rn rnEnd Subrnrnrnrn执行GetDevicePath MyDevInfo时就出现“实时错误49,DLL调用约定错误”rn我把rnPublic Declare Function GetDevicePath _rn Lib "PrinterUsb.dll" _rn (ByRef sDevInfo As DEVINFO) _rnAs Longrn改成rnPublic Declare Function GetDevicePath _rn Lib "PrinterUsb.dll" _rn (ByVal sDevInfo As DEVINFO) _rnAs Longrn就出现“编译错误:用户类型不能用”。rnrn现在怎么办,哪儿错了,要怎么改,原因是什么呢,谢谢!rn
调用约定
__cdcel //调用方平衡堆栈 可以使用复写传播进行优化, 函数内部通常为ret printf("%s\n", "hhe122h"); 00BE1002 xor eax,0BE2090h 00BE1007 push 0BE2100h 00BE100C push 0BE2108h ...
dll文件如何生成符合vc调用约定的lib文件
买了一个Keyence的激光位移传感器,厂家只给了LkIF.h和LkIF.dll两个文件,没有给lib文件,现在我用dumpbin/exports LkIF.dll>lkif.def,产生了lkif.def文件,其代码如下:rn[code=C/C++]rnrnDump of file lkif.dllrnrnFile Type: DLLrnrn Section contains the following exports for LkIF.dllrnrn 0 characteristicsrn 424229D0 time date stamp Thu Mar 24 10:45:36 2005rn 0.00 versionrn 1 ordinal basern 138 number of functionsrn 138 number of namesrnrn ordinal hint RVA namernrn 1 0 00001334 LKIF_AbleCancelrn 2 1 0000105F LKIF_AbleStartrn 3 2 000010B4 LKIF_AbleStoprn 4 3 00001186 LKIF_ClearFigureDatarn 5 4 0000138E LKIF_DataStorageGetDatarn 6 5 0000127B LKIF_DataStorageGetStatusrn 7 6 00001208 LKIF_DataStorageInitrn 8 7 000011F9 LKIF_DataStorageStartrn 9 8 00001023 LKIF_DataStorageStoprn 10 9 00001299 LKIF_GetAbleMinMaxrn 11 A 0000126C LKIF_GetAbleModern 12 B 00001190 LKIF_GetAlarmLevelrn 13 C 000011CC LKIF_GetAnalogScalingrn 14 D 00001127 LKIF_GetAnalogThroughrn 15 E 0000131B LKIF_GetAveragern 16 F 0000101E LKIF_GetCalcDatarn 17 10 000013F2 LKIF_GetCalcMethodrn 18 11 000012AD LKIF_GetCalcModern 19 12 00001258 LKIF_GetCutOffFrequencyrn 20 13 000013AC LKIF_GetDataStoragern 21 14 0000128A LKIF_GetDisplayUnitrn 22 15 00001406 LKIF_GetFigureDatarn 23 16 00001014 LKIF_GetFilterModern 24 17 000010C8 LKIF_GetLightrn 25 18 00001131 LKIF_GetMeasureModern 26 19 00001311 LKIF_GetMutualInterferencePreventionrn 27 1A 00001037 LKIF_GetNumAlarmrn 28 1B 00001078 LKIF_GetOffsetrn 29 1C 00001032 LKIF_GetPanelrn 30 1D 0000114A LKIF_GetProgramNorn 31 1E 000011A9 LKIF_GetReflectionModern 32 1F 000010D7 LKIF_GetSamplingCyclern 33 20 00001271 LKIF_GetScalingrn 34 21 0000128F LKIF_GetStorobeTimern 35 22 00001069 LKIF_GetTimingSynchronizationrn 36 23 00001140 LKIF_GetTolerancern 37 24 000010F0 LKIF_GetToleranceComparatorOutputFormatrn 38 25 0000117C LKIF_GetTriggerModern 39 26 0000141A LKIF_SetAbleMinMaxrn 40 27 0000132A LKIF_SetAbleModern 41 28 000010D2 LKIF_SetAlarmLevelrn 42 29 000012A3 LKIF_SetAnalogScalingrn 43 2A 000012F8 LKIF_SetAnalogThroughrn 44 2B 000011FE LKIF_SetAveragern 45 2C 00001091 LKIF_SetCalcMethodrn 46 2D 000011AE LKIF_SetCalcModern 47 2E 000010A0 LKIF_SetCutOffFrequencyrn 48 2F 0000135C LKIF_SetDataStoragern 49 30 000010A5 LKIF_SetDisplayUnitrn 50 31 0000140B LKIF_SetFilterModern 51 32 000013BB LKIF_SetMeasureModern 52 33 000012DF LKIF_SetModern 53 34 00001352 LKIF_SetMutualInterferencePreventionrn 54 35 000010AA LKIF_SetNumAlarmrn 55 36 0000110E LKIF_SetOffsetrn 56 37 00001401 LKIF_SetPanelrn 57 38 0000134D LKIF_SetPanelLockrn 58 39 00001195 LKIF_SetProgramNorn 59 3A 0000133E LKIF_SetReflectionModern 60 3B 00001393 LKIF_SetResetrn 61 3C 00001087 LKIF_SetSamplingCyclern 62 3D 00001339 LKIF_SetScalingrn 63 3E 00001113 LKIF_SetStorobeTimern 64 3F 000010FF LKIF_SetTimingrn 65 40 00001384 LKIF_SetTimingSynchronizationrn 66 41 000013D4 LKIF_SetTolerancern 67 42 00001136 LKIF_SetToleranceComparatorOutputFormatrn 68 43 0000113B LKIF_SetTriggerModern 69 44 00001145 LKIF_SetZerorn 70 45 00001334 _LKIF_AbleCancel@0rn 71 46 0000105F _LKIF_AbleStart@4rn 72 47 000010B4 _LKIF_AbleStop@0rn 73 48 00001186 _LKIF_ClearFigureData@0rn 74 49 0000138E _LKIF_DataStorageGetData@16rn 75 4A 0000127B _LKIF_DataStorageGetStatus@12rn 76 4B 00001208 _LKIF_DataStorageInit@0rn 77 4C 000011F9 _LKIF_DataStorageStart@0rn 78 4D 00001023 _LKIF_DataStorageStop@0rn 79 4E 00001299 _LKIF_GetAbleMinMax@12rn 80 4F 0000126C _LKIF_GetAbleMode@8rn 81 50 00001190 _LKIF_GetAlarmLevel@8rn 82 51 000011CC _LKIF_GetAnalogScaling@20rn 83 52 00001127 _LKIF_GetAnalogThrough@8rn 84 53 0000131B _LKIF_GetAverage@8rn 85 54 0000101E _LKIF_GetCalcData@8rn 86 55 000013F2 _LKIF_GetCalcMethod@12rn 87 56 000012AD _LKIF_GetCalcMode@8rn 88 57 00001258 _LKIF_GetCutOffFrequency@8rn 89 58 000013AC _LKIF_GetDataStorage@12rn 90 59 0000128A _LKIF_GetDisplayUnit@8rn 91 5A 00001406 _LKIF_GetFigureData@8rn 92 5B 00001014 _LKIF_GetFilterMode@8rn 93 5C 000010C8 _LKIF_GetLight@20rn 94 5D 00001131 _LKIF_GetMeasureMode@8rn 95 5E 00001311 _LKIF_GetMutualInterferencePrevention@4rn 96 5F 00001037 _LKIF_GetNumAlarm@8rn 97 60 00001078 _LKIF_GetOffset@8rn 98 61 00001032 _LKIF_GetPanel@4rn 99 62 0000114A _LKIF_GetProgramNo@4rn 100 63 000011A9 _LKIF_GetReflectionMode@8rn 101 64 000010D7 _LKIF_GetSamplingCycle@4rn 102 65 00001271 _LKIF_GetScaling@24rn 103 66 0000128F _LKIF_GetStorobeTime@4rn 104 67 00001069 _LKIF_GetTimingSynchronization@4rn 105 68 00001140 _LKIF_GetTolerance@16rn 106 69 000010F0 _LKIF_GetToleranceComparatorOutputFormat@4rn 107 6A 0000117C _LKIF_GetTriggerMode@8rn 108 6B 0000141A _LKIF_SetAbleMinMax@12rn 109 6C 0000132A _LKIF_SetAbleMode@8rn 110 6D 000010D2 _LKIF_SetAlarmLevel@8rn 111 6E 000012A3 _LKIF_SetAnalogScaling@20rn 112 6F 000012F8 _LKIF_SetAnalogThrough@8rn 113 70 000011FE _LKIF_SetAverage@8rn 114 71 00001091 _LKIF_SetCalcMethod@12rn 115 72 000011AE _LKIF_SetCalcMode@8rn 116 73 000010A0 _LKIF_SetCutOffFrequency@8rn 117 74 0000135C _LKIF_SetDataStorage@12rn 118 75 000010A5 _LKIF_SetDisplayUnit@8rn 119 76 0000140B _LKIF_SetFilterMode@8rn 120 77 000013BB _LKIF_SetMeasureMode@8rn 121 78 000012DF _LKIF_SetMode@4rn 122 79 00001352 _LKIF_SetMutualInterferencePrevention@4rn 123 7A 000010AA _LKIF_SetNumAlarm@8rn 124 7B 0000110E _LKIF_SetOffset@8rn 125 7C 00001401 _LKIF_SetPanel@4rn 126 7D 0000134D _LKIF_SetPanelLock@4rn 127 7E 00001195 _LKIF_SetProgramNo@4rn 128 7F 0000133E _LKIF_SetReflectionMode@8rn 129 80 00001393 _LKIF_SetReset@4rn 130 81 00001087 _LKIF_SetSamplingCycle@4rn 131 82 00001339 _LKIF_SetScaling@24rn 132 83 00001113 _LKIF_SetStorobeTime@4rn 133 84 000010FF _LKIF_SetTiming@8rn 134 85 00001384 _LKIF_SetTimingSynchronization@4rn 135 86 000013D4 _LKIF_SetTolerance@16rn 136 87 00001136 _LKIF_SetToleranceComparatorOutputFormat@4rn 137 88 0000113B _LKIF_SetTriggerMode@8rn 138 89 00001145 _LKIF_SetZero@8rnrn Summaryrnrn 55000 .datarn 1000 .idatarn 5000 .rdatarn 3000 .relocrn 1000 .rsrcrn 47000 .textrn[/code]rnrn发现了如下问题:rn里面的函数重复出现了,一个无下划线,一个带下划线rn[code=C/C++]rn1 0 00001334 LKIF_AbleCancelrn70 45 00001334 _LKIF_AbleCancel@0rn[/code]rnrn我要用自己编写的VC程序(是VC不是Delphi),调用DLL的函数,我应该怎么修改这个ref文件使之符合vc调用约定呢,重复的函数要怎么处理?那位高手可以指点一下啊?rnrnrnps:lib/def:lkif.def>machine:ix86>out:lkif.lib 这个我是知道的
__stdcall调用约定、C调用约定和__fastcall调用约定
__stdcall调用约定、C调用约定和__fastcall调用约定 __stdcall调用约定、C调用约定和__fastcall调用约定 __stdcall调用约定、C调用约定和__fastcall调用约定 __stdcall调用约定、C调用约定和__fastcall调用约定
C#程序调用VC的dll,那么VC的dll需要声明为哪种调用约定呢?
C#程序调用VC的dll,那么VC的dll需要声明为哪种调用约定呢?是__declspec( dllexport ),还是 __stdcall呢?
cdecl调用约定与 stdcall调用约定,问题。
[b]C语言默认的函数调用约定是cdecl,请问C++默认的函数调用约定是cdecl还是stdcall?[/b]rn我知道Win API函数多采用stdcall调用约定。rn有人说stdcall是C++的默认调用约定,也有人说是cdecl。rn我感觉是cdecl。如果C++默认stdcall调用约定,那么C++调用C语言写的函数,岂不出现函数自身和调用者都恢复堆栈的情况,也就是恢复堆栈两次,那么栈顶指针不就指偏了?
VC中虚函数的问题
代码如下rn********CShape.h*****rn抽象类rnpublic:rn ///
请问VC中的虚函数
大家好。我刚刚接触VC,觉得挺难得,因为前一阵一直在学c语言,一时间很难把面向过程和面向对象弄懂。我想问一下VC中虚函数的作用,即具体用法,向往大家能够帮我。rnrn 小妹感激不尽
请教高手:VB dll 调用约定错误!!
各位高手,我的VB调用DLL,在运行时出现了 dll 调用约定错误! 程序如下,请各位大虾帮忙解决一下!!感恩。。rnrnVB程序:rnrnrnrnOption Explicitrnrn'USB User InterfacernPublic Declare Function Read_USB Lib "DS5000USB_UI.dll" (ByVal mType As Long, ByVal wLength As Long, pBuffer As Any) As BooleanrnPublic Declare Function Write_USB Lib "DS5000USB_UI.dll" (ByVal cChar As Long) As BooleanrnrnGlobal Const USB_READ_CMD_REDAY = 0rnGlobal Const USB_READ_CMD_DATA = 1rnGlobal Const ARRAYSIZE = 1024 ' Size of read bufferrnGlobal DSO_IOInitOK As BooleanrnGlobal USB_TimeOutTimer As Long 'USB´«Êä½áÊøʱ¼ärnrnrnSub USB_Init()rn' ========================================================================rn'rn' INITIALIZATION SECTIONrn'rn' ========================================================================rnrn ' The application brings the oscilloscope online using ildev. Arn ' device handle, Dev, is returned and is used in all subsequentrn ' calls to the device.rn Dim retcode As Booleanrn Dim ValueStr As String * ARRAYSIZErn Dim buf(255) As Bytern ' The application reads the ASCII string from the oscilloscopern ' into the ValueStr variable.rn retcode = Read_USB(USB_READ_CMD_REDAY, 1, buf(0))rn rn If retcode = False Thenrn MsgBox "Cann't Connect to USB Device", 48, "USB Init"rn DSO_IOInitOK = Falsern Elsern DSO_IOInitOK = Truern End Ifrn rnEnd SubrnSub SendToUSB(cmd As String)rn Dim retcode As Booleanrn Dim buf As Stringrn Dim temp As Longrn Dim i As Integerrn rn buf = cmd + Chr$(13)rnrn ' The application writes the text in ScopeCommand to thern ' oscilloscope.rn For i = 1 To Len(cmd) + 1rn temp = Asc(buf)rn buf = Right(buf, Len(cmd) + 1 - i)rn retcode = Write_USB(temp)rn If retcode = False Thenrn MsgBox "Cann't Connect to USB Device", 48, "USB Send Message"rn Exit Forrn End Ifrn Next irnrnEnd SubrnPublic Function ReadUSB() As Stringrnrn Dim retcode As Booleanrn Dim tmpStr As Stringrn Dim buffer(256) As Bytern Dim i, size As Longrn ' The application reads the ASCII string from the oscilloscopern ' into the ValueStr variable.rn USB_TimeOutTimer = 0rn buffer(0) = 0rn While (buffer(0) = 0 And USB_TimeOutTimer < 20)rn retcode = Read_USB(USB_READ_CMD_REDAY, 1, buffer(0))rn If retcode = False Thenrn MsgBox "Can't Connect to USB Device", 48, "USB Read Message"rn ReadUSB = ""rn Exit Functionrn End Ifrn DoEventsrn Wendrn If USB_TimeOutTimer > 19 Thenrn MsgBox "Read USB time out", 48, "USB Read Message"rn tmpStr = ""rn Elsern size = buffer(0)rn retcode = Read_USB(USB_READ_CMD_DATA, size, buffer(0))rn If retcode = False Thenrn MsgBox "Cann't Connect to USB Device", 48, "USB Read Message"rn ReadUSB = ""rn Exit Functionrn End Ifrn tmpStr = ""rn For i = 0 To size - 1rn If (buffer(i) = 10) Thenrn Exit Forrn End Ifrn tmpStr = tmpStr + Chr(buffer(i))rn Next irn End Ifrn ReadUSB = tmpStrrn rnEnd FunctionrnrnrnrnrnDLL函数定义:rnrn(DLL头文件)rnrn// DS5000USB_UI.h : main header file for the DS5000USB_UI DLLrn//rnrn#if !defined(AFX_DS5000USB_UI_H__A004624B_F508_4C1D_B0A9_5ABF16885DC8__INCLUDED_)rn#define AFX_DS5000USB_UI_H__A004624B_F508_4C1D_B0A9_5ABF16885DC8__INCLUDED_rnrn#if _MSC_VER > 1000rn#pragma oncern#endif // _MSC_VER > 1000rnrn#ifndef __AFXWIN_H__rn #error include 'stdafx.h' before including this file for PCHrn#endifrnrn#include "resource.h" // main symbolsrnrn#define USB_CTRL_TYPE_LEN 0//¶Á´«ÊäµÄÊý¾ÝµÄ³¤¶Èrn#define USB_CTRL_TYPE_DATA 1//¶Á´«ÊäµÄÊý¾Ýrnrnextern "C" BOOL EXPORT __stdcall Control_Command_Send(INT devIndex,INT mRequest,INT wValue,INT wIndex,INT wLength);rnextern "C" BOOL EXPORT __stdcall Control_Command_Receive(INT devIndex,INT mRequest,INT wValue,INT wIndex,INT wLength,PUCHAR mBuffer);rnextern "C" BOOL EXPORT __stdcall Bulk_DataTransfer_Read(INT devIndex,INT wLength,PUCHAR mBuffer);rnextern "C" BOOL EXPORT __stdcall Bulk_DataTransfer_Write(INT devIndex,INT wLength,PUCHAR mBuffer);rnextern "C" INT EXPORT __stdcall GetDeviceNum();//»ñÈ¡µ±Ç°ÏµÍ³ÖеÄRIGOL ·ÇTMCÉ豸×ÜÊýrn/*******************************************************************************rnrn ** º¯ÊýÃû³Æ: Read_USB rn ** ÊäÈë²ÎÊýrn ** devIndex --- É豸±àºÅ rn ** type --- ¶ÁÈ¡ÀàÐÍΪÊý¾Ý³¤¶È(USB_CTRL_TYPE_LEN)»òÊý¾ÝÄÚÈÝ(USB_CTRL_TYPE_DATA)rn ** wLength --- ±¾´Î¶ÁÈ¡µÄ³¤¶Èrn ** mBuffer --- ´æ´¢¶ÁÈ¡Êý¾ÝµÄ¿Õ¼äÖ¸Õërn **rn ** Êä³ö²ÎÊý:rn ** ·µ»ØÀàÐÍ --- BOOLÀàÐÍrn **rn ** Ãè Êö: ¶ÁÈ¡USBÊý¾Ýrn********************************************************************************/rnextern "C" BOOL EXPORT __stdcall Read_USB(INT devIndex,INT type,INT wLength,PUCHAR mBuffer);rn/*******************************************************************************rnrn ** º¯ÊýÃû³Æ: Write_USB rn ** ÊäÈë²ÎÊýrn ** devIndex --- É豸±àºÅ rn ** chr --- Ҫͨ¹ýUSB·¢Ë͵ÄÊý¾Ýrn **rn ** Êä³ö²ÎÊý:rn ** ·µ»ØÀàÐÍ --- BOOLÀàÐÍrn **rn ** Ãè Êö: ·¢ËÍUSBÊý¾Ýrn********************************************************************************/rnextern "C" BOOL EXPORT __stdcall Write_USB(INT devIndex,UCHAR chr);rnrnHANDLE OpenDeviceByIndex(INT index);rnBOOL CloseDeviceByIndex(INT index);rn//BOOL Close_Device_Handle();rnrnrn#define MAX_BULK_INBUF_SIZE 4096rn#define MAX_BULK_OUTBUF_SIZE 4096rnrn#define MAX_CONTROL_INBUF_SIZE 512rn#define MAX_CONTROL_OUTBUF_SIZE 512rnrnrnBOOL CloseIfOpen(VOID);rnBOOL Exit(INT res);rnrnextern HANDLE OpenByInterface(rn GUID* pClassGuid, // points to the GUID that identifies the interface classrn DWORD instance, // specifies which instance of the enumerated devices to openrn PDWORD pError // address of variable to receive error statusrn );rnrn/////////////////////////////////////////////////////////////////////////////rn// CDS5000USB_UIApprn// See DS5000USB_UI.cpp for the implementation of this classrn//rnrnrnclass CDS5000USB_UIApp : public CWinApprnrnpublic:rn CDS5000USB_UIApp();rnrn// Overridesrn // ClassWizard generated virtual function overridesrn //AFX_VIRTUAL(CDS5000USB_UIApp)rn public:rn virtual void OnFinalRelease();rn //AFX_VIRTUALrnrn //AFX_MSG(CDS5000USB_UIApp)rn // NOTE - the ClassWizard will add and remove member functions here.rn // DO NOT EDIT what you see in these blocks of generated code !rn //AFX_MSGrn DECLARE_MESSAGE_MAP()rn;rnrnrn/////////////////////////////////////////////////////////////////////////////rnrn//AFX_INSERT_LOCATIONrn// Microsoft Visual C++ will insert additional declarations immediately before the previous line.rnrn#endif // !defined(AFX_DS5000USB_UI_H__A004624B_F508_4C1D_B0A9_5ABF16885DC8__INCLUDED_)rnrn
关于vc的纯虚函数和虚函数
刚开始学vc有个问题 看书老是不能全理解 ,就是:rnrn父类中如果有个纯虚函数 在父类中这个纯虚函数是不进行定义的 ,就声明了一下,他必须要子类来继承重写才能用,那何必有纯虚函数了,在子类中我重新定义一个函数就行了 何必继承父类的虚函数呢
各位大虾帮忙啊,dll 调用约定错误!!!!
[code=C/C++]rnEXPORTSrn addrnlong add(long var1,long var2)rnrn return var1+var2;rnrnrn[/code]rn[code=VB]rnPrivate Declare Function add Lib "..\JAPI.dll" (ByVal var1 As Long, ByVal var2 As Long) As LongrnrnPrivate Sub Command1_Click()rn Text3.Text = add(CLng(Text1.Text), CLng(Text2.Text))rnEnd Subrnrn[/code]rnrn运行到add函数时,dll 调用约定错误!!!!
实时错误‘49’,DLL调用约定错误?
在VB中调用一个C语言的DLL:调试时出现如题所说错误,但生成EXE却可以执行并不出错,请问是何原因?rnrnPrivate Declare Function OnReset Lib "D:\v2\Card_Dll.dll" (ByVal com As String) As LongrnrnrnPublic Function OnReset_Card(ByVal com As String) As Longrn OnReset_Card = OnReset("com1")rnEnd FunctionrnrnPrivate Sub Command1_Click()rn MsgBox OnReset_Card("COM1")rnEnd Subrnrn关于这个DLL中的函数,文档是这样说的:rn函数名:BOOL OnReset(char com[]);rn功能:对磁卡机进行硬复位;rn返回类型:True--成功,False--失败;rn参数说明:com[ ]--串口号,字符串方式,如:”com1”;rn备注:无;rn
DLL的调用约定问题,请高手指教!!!
我写了两个DLLrn第一个DLL中输出函数声明为rndouble WINAPI add(double x,double y)rn并且在def文件中标明了入口rn第二个DLL中输出函数声明为rnextern "C" double __declspec(dllexport) add(double x,double y)rn没有写def文件rn第一个DLL可以被VB调用,但不能被VC显式调用(没试过隐式调用)rn第二个DLL可以被VC显式调用,但不能被VB调用(错误为DLL调用约定错误)rn请教高手,我要是想写一个DLL可以被VB、VC都能调用,输出函数应该怎么声明?
调用DLL运行时提示出错(调用约定不一致?)
我调用一个dll,编译时正常通过,但是运行时提示出错,出错信息如下:rnRun-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.rnrndll导出类的头文件:rn[code=c]rn#ifndef TDI_Hrn#define TDI_Hrnrn#ifdef _CLASSINDLLrn #define CLASSINDLL_CLASS_DECL __declspec(dllexport)rn#elsern #define CLASSINDLL_CLASS_DECL __declspec(dllimport)rn#endifrnrn#define TDI_VER 1rn#define TDI_SPD 2rn//#define TDI_LINES 3rn//#define TDI_GAIN 4rn#define TDI_GAIN_V2 3rn//#define TDI_OFFSET 5rn#define TDI_OFFSET_V2 4rn//#define TDI_V2_GAIN_OFFSET 3rn#define TDI_CMD_END 0x0Drn#define TDI_CMD_END2 0x0Arnrnrn#define ERR_TDI_232_DISCONNECT -1rn#define ERR_TDI_232_NORESPOND -2rn#define ERR_TDI_PCI_NOHANDLE -3rn#define ERR_TDI_PCI_FUNCNOLOAD -4rn#define ERR_TDI_CMD_OK 1rn#define ERR_TDI_CMD_SYNTAXERR -5//srn#define ERR_TDI_CMD_UNKNOWN -6rnrn#define TDI_SENSORNUM 20rn#define TDI_SENSOR_PIXELNUM 143rn#define TDI_AVAILABLE_SENSOR_PIXELNUM 138rn#define TDI_AVAILABLE_SENSOR_PIXELNUM_OFFSET 2 rn#define TDI_UNCERTAIN_LINES 20rnrn#define TDI_STAR 1rn#define TDI_STOP 2rn#define TDI_HVOLTAGE_ON 3rn#define TDI_HVOLTAGE_OFF 4rnrn#define TDI_INTEGRAL_FACTOR 0.75/270.0rnrn#define TDI_PIXEL_MEASURE 15.0rn#define TDI_LINE_INTEGRAL_TIME(value) TDI_INTEGRAL_FACTOR*valuern#define TDI_LINE_TRANS_TIME(value) TDI_INTEGRAL_FACTOR*1000+(value-270)*TDI_INTEGRAL_FACTORrnclass USCrn public:rn BYTE high ;rn BYTE low ;rn USC()high=0;low=0;rn USC(BYTE h,BYTE l)rn rn high=h;rn low=l;rnrn rnrn ;rnrn#pragma comment(lib,"TDIcom.lib")rnclass CLASSINDLL_CLASS_DECL LibTDI rnrnrn void OnWait();rn BYTE checksum(BYTE *list,WORD len);rn WORD BinToInt(USC c) ;rn USC IntToBin(WORD c) ;rn rn public:rn //LibTDI();rn bool Connect();rn void Disconnect();rn BOOL CheckConnection();rnrn int Get_TDI_V2(int code,int para);rn BOOL Set_TDI_V2(int code,int para,int para2);rn BOOL TDI_SwitchGear(int type) ;rnrnrn;rnrn#endifrn[/code]rnrndll对应的def文件信息:rn[code=text]rnLIBRARY TDICOM.DLLrnrnEXPORTSrn ?BinToInt@LibTDI@@QAEGVUSC@@@Z @2 ; LibTDI::BinToInt(USC)rn ?CheckConnection@LibTDI@@QAEHXZ @6 ; LibTDI::CheckConnection()rn ?Connect@LibTDI@@QAE_NXZ @1 ; LibTDI::Connect()rn ?Disconnect@LibTDI@@QAEXXZ @5 ; LibTDI::Disconnect()rn ?Get_TDI_V2@LibTDI@@QAEHHH@Z @8 ; LibTDI::Get_TDI_V2(int, int)rn ?IntToBin@LibTDI@@QAE?AVUSC@@G@Z @3 ; LibTDI::IntToBin(unsigned short)rn ?OnWait@LibTDI@@QAEXXZ @7 ; LibTDI::OnWait()rn ?Set_TDI_V2@LibTDI@@QAEHHHH@Z @9 ; LibTDI::Set_TDI_V2(int, int, int)rn ?TDI_SwitchGear@LibTDI@@QAEHH@Z @10 ; LibTDI::TDI_SwitchGear(int)rn ?checksum@LibTDI@@QAEEPAEG@Z @4 ; LibTDI::checksum(unsigned char *, unsigned short)rn ___CPPdebugHook @11 ; ___CPPdebugHookrn[/code]rnrn我搜了一下,似乎是调用约定不一致的问题(我项目的调用约定是__cdecl (/Gd)),但是我改了改也还是不行,不知道该怎么改?rn
vb调试时出现dll调用约定错误?
dll中定义rnDECLSPEC int __cdecl CLOpenUSBSerialDevice(int ComNumber);rnrn我在vb中声明如下:rnPublic Declare Function CLOpenUSBSerialDevice Lib "E:\CLDevice\CLDevIFace.dll" (comnumber As Integer) As IntegerrnPublic handle As Integerrnrn调用时:handle = CLOpenUSBSerialDevice(11)rn老是提示dll调用约定错误!!!rnrnrn跪求大神指点啊。
百思不得其解,GetForm出现“DLL调用约定错误”
Public Function ReturnForm(pFormName As String) As FORM_INFO_1rn Dim PrinterHandle As Long ' 打印机句柄rn Dim pFI1 As FORM_INFO_1rn Dim Temp() As Bytern Dim BytesNeeded As Longrn Dim RetVal As Longrn rn If OpenPrinter(Printer.DeviceName, PrinterHandle, 0&) = 0 Then Exit Function ' 返回一个打印机句柄rn rn ReDim Temp(0)rn RetVal = GetForm(PrinterHandle, pFormName, 1, Temp(0), 0&, BytesNeeded)rn ReDim Temp(BytesNeeded)rn rn If GetForm(PrinterHandle, pFormName, 1, Temp(0), BytesNeeded, BytesNeeded) = 0 Thenrn Debug.Print "错误:" & Err.LastDllErrorrn Elsern Debug.Print "成功返回" & pFormNamern End Ifrn Call CopyMemory(pFI1, Temp(0), BytesNeeded)rn ReturnForm = pFI1rn Call ClosePrinter(PrinterHandle)rnEnd Functionrnrn该函数能正常返回,但对于某些特定的pFormName,却会出现“DLL调用约定错误”,比如:rnReturnForm "A3 Extra Transvers"时就会出现此错误rnReturnForm "A3 Extra Transver" 就不会出现此错误("A3 Extra Transver"是我自定义的Form)rnrn而且错误是在函数正常结束后出现的,此时函数也已经正常返回了pFI1的值。rnrn代码方面我想是不会有问题的,实在不知道这个错误从何而来。
DLL调用约定出错的问题(在线等候)
我现在调用VC写的DLL时遇到一个很老火的问题:rnDLL文件名:AVPlayer.dll。rn在AVPlayer.h中定义了DLLEXPORT_API int __stdcall PB_IniPlayer(HANDLE *pPlayHandle,HWND hWnd,BOOL bIsRemotePlayBack = FALSE);rn在VB的Module里面我申明了Declare Function PB_IniPlayer Lib "AVPlayer.dll" (ByVal nPort As Long, ByVal hWnd As Long, ByVal bIsRemotePlay As Long) As Longrn然后在用的时候:Dim Gl_Ret As Long rnGl_Ret = PB_IniPlayer(0, Picture1.hWnd, 1),就一直说“DLL调用约定错误”;rn我已经试过把 bIsRemotePlay 定义成其他类型,但是都有错,只有不定义 bIsRemotePlay ,即:Declare Function PB_IniPlayer Lib "AVPlayer.dll" (ByVal nPort As Long, ByVal hWnd As Long) As Long,然后Gl_Ret = PB_IniPlayer(0, Picture1.hWnd),才不报错,但是达不到程序要求啊。哪位高手指点啊!
VC如何编译存在不同调用约定的程序
如果程序用的库中存在不同调用约定的函数,在dll中或者静态lib中.VC中如何编译这个程序,我一直不知道咋搞,希望兄弟帮忙,谢谢
“运行时错误'49',DLL调用约定错误。”,怎么解决?
Private Declare Function GetIdeSerialNumber Lib "D:\Project\GetHdSn\LGETHDSN.DLL" (ByVal driveno As Integer, ByRef SerialNo As String) As LongrnrnPrivate Sub Command1_Click()rn rn Dim dn As Integerrn dn = 0rn Dim sn As Stringrn sn = String$(100, " ")rn Call GetIdeSerialNumber(0, sn)rn rnEnd Subrn
DLL 调用约定错误如何解决啊
Private Declare Function OSfCreateShellLink Lib "Vb5stkit.dll" Alias "fCreateShellLink" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArguments As String) As LongrnPrivate Sub Command2_Click()rn If Text1.Text = "" Thenrn MsgBox "游戏路经不能为空", , "提示"rn Text1.SetFocusrn Elsern If Text2.Text = "" Thenrn MsgBox "游戏名称不能为空", , "提示"rn Text2.SetFocusrn Elsern lresult = OSfCreateShellLink("..\..\desktop", Text2.Text, Text1.Text, "")rn End Ifrn End Ifrn rnEnd Subrnrn程序运行的时候提示DLL 调用约定错误,请问如何解决啊rn谢谢了
关于VC编译器中设置调用约定的问题
最近看一片文章上介绍说,VC的编译器把.c文件按照_cdecl方式编译,把.cpp文件按照_stdcall方式编译。但是我发现VC中可以设置“调用约定” 而默认的都是_cdecl方式,那我就觉得矛盾了,调用方式到底是编译器设置觉得的,还是通过文件的扩展名(.c .cpp)来决定的?而且如果不是按照扩展名来决定编译调用方式,那不是.c和.cpp都无所谓了?
DLL调用,实时错误“49”:DLL调用约定错误
小弟做一个摄像头控制程序,需要调用摄像头厂家给的DLL,厂家给的VC.NET函数声明如下:rnextern "C"rnrnrn //how to enumerate multi-device, and select one to handle.rn //first enumerate devices that are connecting to the PC(call GetVMCUVCDevCount()s).rn //if you would like to print the device name string (call GetDevFriendlyNameByIndex())rn //second, attach the special device you like.(using AttachUVCDeviceByIndex() function)rn //end, detach all device(using DetachUVCDeviceALL())rn DECLDIR ULONG GetVMCUVCDevCount();rn DECLDIR ULONG GetDevFriendlyNameByIndex(ULONG iIndex,TCHAR *DevName, ULONG DevNamesize);rn DECLDIR BOOL AttachUVCDeviceByIndex(ULONG iIndex);rn DECLDIR VOID DetachUVCDeviceALL();rnrn //TRUE for a successful call, FALSE for any error.rn //1 for Pressing the Snapshot key, 0 for no operation.rn DECLDIR BOOL GetSnapShotStatus(BYTE *SnapShotbStatus);rnrn我在VB中声明如下:rnPrivate Declare Function GetSnapShotStatus Lib "UVCXUControl.dll" (ByRef Parm As Long) As BooleanrnPrivate Declare Function GetVMCUVCDevCount Lib "UVCXUControl.dll" () As LongrnPrivate Declare Function AttachUVCDeviceByIndex Lib "UVCXUControl.dll" (ByVal iIndex As Long) As BooleanrnPrivate Declare Sub DetachUVCDeviceALL Lib "UVCXUControl.dll" ()rn其中GetVMCUVCDevCount 可用,调用GetSnapShotStatus 时一直提醒实时错误“49”:DLL调用约定错误,rn望高人帮忙解决!rn谢谢rn
vba调用cb的dll问题:“dll调用约定错误”
我在cb中编译的dll,用cb测试调用没问题,但vba调用时出现“dll调用约定错误”。rndll接口如下:rnextern "C" __declspec(dllexport) double cp(char *code);rndouble cp(char *code)rnrn return _qtn->cp(code);rnrnrnrnvba中调用代码:rnPrivate Declare Function cp Lib "PGetQsr.dll" Alias "_cp" (ByVal a1 As String) As Doublern rnDim a As Doublerna = cp("SHFIF1311") //这一行出现报错:"运行时错误49,dll调用约定错误"rnrn是不是声明问题,请高手指正。
相关热词 c#检测非法字符 c#双屏截图 c#中怎么关闭线程 c# 显示服务器上的图片 api嵌入窗口 c# c# 控制网页 c# encrypt c#微信网页版登录 c# login 居中 c# 考试软件