to happyangelclc(快乐), 我在MSDN上看到有这么一段话“A module-definition (.DEF) file is a text file containing one or more module statements that describe various attributes of a DLL. If you are not using the __declspec(dllexport) keyword to export the DLL’s functions, then the DLL requires a .DEF file. ”好像说如果没有用__declspec(dllexport) 关键字来导出DLL的话,才需要.DEF文件,而我已经用了__declspec(dllexport) 了,所以就应该不用.DEF文件了吧
to vcs(游魂) 还是老样子,提示“DLL调用约定错误”各位大哥,都没有碰到过这个问题吗,我在VC下调用这个DLL都是好的!!!
我比较了一下标准的WINAPI调用,例如调用kernel32.dll 里面的"GetFileAttributes"函数,vb是这么写的: Public Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long在MSDN中找到了GetFileAttributes函数的定义 DWORD GetFileAttributes( LPCTSTR lpFileName // pointer to the name of a file or directory ); 明明是我的函数参数和它是差不多的嘛,为什么WINAPI的可以,而我的却不行呢??????
在vc中,将"LPTSTR"改为"LPCTSTR" 或者 在VB中将ByVal去掉
标准答案: int _stdcall fileproc(LPTSTR FileNameIn,LPTSTR FileNameOut) {} //as intger 最好为as long
to ls9d999999(小菜) 是: extern "C" __declspec(dllexport) int _stdcall fileproc(LPTSTR FileNameIn,LPTSTR FileNameOut) 吗?我也试过了,好像还是不行
这问题问过很多边了,你的VC动态库里函数extern "C" __declspec(dllexport)写了吗?或者写了还不行,那你在动态库的工程里加一个.def文件来EXPORT所有你想让外部调用的接口。vc 的dllint WINAPI DialConnect(){ MessageBox(NULL,"99","00",MB_OK); return 0;}vc的.def; vctest.def : Declares the module parameters for the DLL.LIBRARY "vctest"DESCRIPTION 'vctest Windows Dynamic Link Library'EXPORTS ; Explicit exports can go here DialConnectvb的模块Attribute VB_Name = "Module1"Public Declare Function DialConnect Lib "VCtest.dll" () As Longvb的调用 DialConnect
to lhrtm(天涯人),谢谢,问题解决,高手!!我是初学者,ATL好像太复杂了,不是很明白,有空向你请教,我的QQ是:699321,E-MAIL:[email protected]
extern "C"{
#endif
...
//你的dll程序主体#ifdef __cplusplus
}
#endif记着给分哦,不然我不理你了
还是老样子,提示“DLL调用约定错误”各位大哥,都没有碰到过这个问题吗,我在VC下调用这个DLL都是好的!!!
VB的String构造不一样的,你试试将String拷贝到Byte数组(注意要符合C语言格式的chr(0)结尾)
然后再传进去..
Public Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long在MSDN中找到了GetFileAttributes函数的定义
DWORD GetFileAttributes(
LPCTSTR lpFileName // pointer to the name of a file or directory
);
明明是我的函数参数和它是差不多的嘛,为什么WINAPI的可以,而我的却不行呢??????
在VB中将ByVal去掉
int _stdcall fileproc(LPTSTR FileNameIn,LPTSTR FileNameOut) {}
//as intger 最好为as long
extern "C" __declspec(dllexport) int _stdcall fileproc(LPTSTR FileNameIn,LPTSTR FileNameOut)
吗?我也试过了,好像还是不行
步骤:
打开VC下project->Setting->c++面板->Category->code Generation项
->设置calling convention ->选择_stdll
DLL是老方法了,为什么不用ATL做了