调用从VB6 DLL函数 [英] Calling DLL functions from VB6

查看:334
本文介绍了调用从VB6 DLL函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows DLL我写的,写的C / C ++(所有导出的函数是'C')。该DLL工作正常,我在VC ++。我已经给了DLL到另一家公司谁做他们所有的发展VB。他们似乎有链接到功能的问题。我没有用VB在十年,我甚至不安装它。可能是什么问题?

I've got a Windows DLL that I wrote, written in C/C++ (all exported functions are 'C'). The DLL works fine for me in VC++. I've given the DLL to another company who do all their development in VB. They seem to be having a problem linking to the functions. I haven't used VB in ten years and I don't even have it installed. What could be the problem?

我宣布我的所有的公共职能如下:

I've declared all my public functions as follows:

#define MYDCC_API __declspec(dllexport)


MYDCCL_API unsigned long MYDCC_GetVer( void);
.
.
.

任何想法?

最后一回到今天这个并将它的工作。的回答让我在​​正确的轨道上,但我发现这个最有用的:

Finally got back to this today and have it working. The answers put me on the right track but I found this most helpful:

HTTP://www.$c$cproject.com/KB/ DLL / XDllPt2.aspx

另外,我不得不通过字符串的DLL函数的一些问题,我发现这是很有帮助:

Also, I had a few problems passing strings to the DLL functions, I found this helpful:

HTTP://www.flip$c$c.com/archives/ Interfacing_Visual_Basic_And_C.shtml

推荐答案

通过使用 __ declspec 用于出口,函数名会得到出口的错位的,即包含类型信息,以帮助C ++编译器解决重载。

By using __declspec for export, the function name will get exported mangled, i.e. contain type information to help the C++ compiler resolve overloads.

VB6不能处理错位的名称。作为一种变通方法,你必须去裂伤的名称。最简单的方法是使用导出定义链接DLL文件在VC ++ 文件。出口定义文件非常简单,只包含DLL的名称和导出的函数列表:

VB6 cannot handle mangled names. As a workaround, you have to de-mangle the names. The easiest solution is to link the DLL file using an export definition file in VC++. The export definition file is very simple and just contains the name of the DLL and a list of exported functions:

LIBRARY mylibname
EXPORTS
    myfirstfunction
    secondfunction

此外,你必须指定 STDCALL 调用约定,因为这是唯一调用约定VB6可以处理。有使用汇编注射处理C呼叫的项目,但我猜你不想使用这个困难且容易出错的方法。

Additionally, you have to specify the stdcall calling convention because that's the only calling convention VB6 can handle. There's a project using assembly injection to handle C calls but I guess you don't want to use this difficult and error-prone method.

这篇关于调用从VB6 DLL函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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