VB调用C++标准dll

gooore 2010-06-08 04:33:12
为了测试dll,我用C++模板做了一个简单的标准dll。导出了一个函数和一个类,但是在VB调用的时候,发现编译器果然把函数的名字给处理了。所以我声明的时候只能写成"?fnWinAPI_DLL@@YAHXZ",才能正确运行。

请教各位,有什么好的办法?


'Custom Dll
Private Declare Function fnWinAPI_DLL Lib "WinAPI_DLL.dll" Alias "?fnWinAPI_DLL@@YAHXZ" () As Long




// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the WINAPI_DLL_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// WINAPI_DLL_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef WINAPI_DLL_EXPORTS
#define WINAPI_DLL_API __declspec(dllexport)
#else
#define WINAPI_DLL_API __declspec(dllimport)
#endif

// This class is exported from the WinAPI_DLL.dll
class WINAPI_DLL_API CWinAPI_DLL {
public:
CWinAPI_DLL(void);
// TODO: add your methods here.
};

extern WINAPI_DLL_API int nWinAPI_DLL;

WINAPI_DLL_API int fnWinAPI_DLL(void);



...全文
280 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
gooore 2010-06-10
  • 打赏
  • 举报
回复
不太确定你的具体意思。

并不是完全不能调用的,如果dll同时导出类和函数,可以确定的是函数是可以被调用的。但是导出的类和全局变量就不确定能不能被调用了。

[Quote=引用 3 楼 wangli820 的回复:]
VB是不能调用导出类的DLL的,你要导出原始的extern "c"风格的函数
[/Quote]
gooore 2010-06-10
  • 打赏
  • 举报
回复
是的。

[Quote=引用 2 楼 yangzn76 的回复:]
加一个DEF文件
样子如下:
LIBRARY DllTestDef
EXPORTS
fnWinAPI_DLL
[/Quote]
wangli820 2010-06-09
  • 打赏
  • 举报
回复
VB是不能调用导出类的DLL的,你要导出原始的extern "c"风格的函数
yangzn76 2010-06-08
  • 打赏
  • 举报
回复
加一个DEF文件
样子如下:
LIBRARY DllTestDef
EXPORTS
fnWinAPI_DLL
孤独剑_LPZ 2010-06-08
  • 打赏
  • 举报
回复
Private Declare Function fnWinAPIDLL Lib "WinAPI_DLL.dll" Alias "fnWinAPI_DLL" () As Long
可能的原因:函数名是不标准的名称,最好不要带下划线或别的特殊字符,Alias后面的fnWinAPI_DLL,必须是dll里实际的函数名字,fnWinAPIDLL 不是真实的名字

Declare语句中的Alias子句是一个可选的部分,用户可以通过它所标识的别名对动态库中的函数进行引用。例如,在下面的语句中,声明了一个在VB中名为MyFunction的函数,而它在动态库Mydll.dll中最初的名字是MyFunctionX。
Private Declare Function MyFunction Lib "Mydll.dll" Alias "MyFunctionX" ( ) As Long

需要注意的是,Alias子句中的函数名是大小写敏感的,也就是说,必须与函数在生成时的声明(如在C源文件中的声明)一致。这是因为32位动态库与16位动态库不同,其中的函数名是区分大小写的。同样道理,如果没有使用Alias子句,那么在Function(或Sub)后的函数名也是区分大小写的。

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧