在 VB6 中使用 C++ DLL [英] Use C++ DLL with VB6

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

问题描述

我刚刚在 MSVC++2010 中为我的老板创建了一个 DLL.我选择了带有导出符号"选项的新 Win32 DLL",所以一切都是完全标准的.新项目文件中有一些预定义的导出,一个类,它的构造函数,一个全局函数和带有虚假值的变量,以及一个带有 APIENTRY 函数的文件 dllmain.cpp.我什么都没改变.

I just created a DLL for my boss in MSVC++2010. I selected "New Win32 DLL" with option "Export symbols", so, everything is completely standard. There are some predefined exports in the new project files, a class, its constructor, a global function and variable with bogus values and a file dllmain.cpp with an APIENTRY function. I changed nothing yet.

现在我的老板想在他的 VB6 项目中使用导出的东西.他开始了一个 VB6 项目,做了菜单项目"-链接"(从德语翻译成英语,所以可能有些不同,但我相信你知道我的意思)并选择了一个 DLL 文件,就像他说的那样通常会.

Now my boss wants to use the exported things in his VB6 project. He started a VB6 project, did menu "Project" - "Links" (translated from German to English, so it might be somewhat different but I'm sure you know what I mean) and selected a DLL file, just as he says he usually does.

但是,VB6 无法包含它,而是显示错误消息无法包含 DLL 文件"(没有给出真正的原因).来自 Visual C++ 6 的标准新 DLL 项目也是如此.我的老板认为这可能是因为符号没有真正导出,或者 VB6 需要一些特殊的声明.有谁知道问题出在哪里?

However, VB6 fails to include it, instead showing an error message "could not include DLL file" (no real reason given). The same occurred with a standard new DLL project from Visual C++ 6. My boss thinks it might be because the symbols are not really exported or VB6 needs some special declarations. Does anyone know what the problem is?

推荐答案

是的,VB6 不能那样工作.您需要在 VB 代码中声明 DLL 函数,如下所示:

Yeah, VB6 doesn't work like that. You need to declare the DLL functions in your VB code somewhat like this:

Private Declare Function WinHelp Lib "user32" Alias "WinHelpA" _
  (ByVal hwnd As Long, ByVal lpHelpFile As String, _
  ByVal wCommand As Long, ByVal dwData As Long) As Long

您可以将user32"替换为MyCPlusPlusDLL.dll",并使用 DLL 中的实际方法名称和签名等.然后把 DLL 放到你的/System 文件夹中就可以了.

You would replace "user32" with "MyCPlusPlusDLL.dll" and use the actual method names and signatures etc. from your DLL. Then put the DLL in your /System folder and you should be good to go.

注意:这是假设 C++ DLL 中的方法用__declspec"声明的.

Note: this is assuming that the methods inside your C++ DLL are declared with "__declspec".

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

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