在VS2008中创建C ++ dll,并在Vb6或Delphi中使用 [英] Create C++ dll in VS2008 and use in Vb6 or Delphi

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

问题描述

你好编码员,

我一直在努力寻找互联网,以找到解决我的编码问题的方法.

我们有一些用Delphi4编写的旧代码,这些代码使用了VC6中创建的Ocx.到现在为止,一切都很好.创建的Ocx与不再制造的HW卡进行了通信.现在,新的硬件卡具有在VS2008(C ++)中创建的一些示例代码,而我想做的就是获取此代码,将其转换为dll,并在delphi4中使用此dll.

每次我在VS2008中制作C ++ Dll并尝试在VB6或delphi中运行它时,如果我使用CreateObject或LoadLibrary,都会收到无法创建ActiveX"错误,并且如果尝试手动将其添加为参考,则会收到加载错误,如下所示:好吧.有没有人有一些示例代码,我可以在其中使用C ++在VS2008中创建一个DLL,然后将其部署在Vb6和/或Delphi4中?
谢谢您的帮助.

Hello coders,

I have been trying to scout the internet to find a solution to my coding problem.

We have some legacy code written in Delphi4 which uses an Ocx created in VC6. This was working fine until now. The Ocx that was created communicated with a HW card which no longer is manufactured. Now the new HW card has some sample code that is created in VS2008 (C++), and what I would like to do is take this code, convert it into a dll and use this dll in delphi4.

Everytime I make a C++ Dll in VS2008 and try to run it in VB6 or delphi I get a "Cant create ActiveX" error if I use CreateObject or LoadLibrary, and if I try to add it manually as a reference I get a load error as well. Does anyone have some samle code where I can create a DLL in VS2008 using C++ and then deploying it in Vb6 and/or Delphi4???

Thank you for your help.

推荐答案

通常,由两个不同的编译器开发的C ++ dll彼此不兼容.

一种简单的解决方案是使用工厂方法创建对象.
您的工厂方法应使用
Generally C++ dlls developed by two different compilers are not compatible to each other.

one simple solutions is to create the object in a factory method.
Your factory method should be exported with
extern "C"


导出
这将消除您的名称更改障碍,您可以加载库.



This will remove your name mangling hurdles and you can load the library.


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

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