Use C++ DLL with VB6

做~自己de王妃 提交于 2019-11-30 23:22:43

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

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.

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

I see you already accepted an answer, but this may be of use to you or others. The Universal DLL Function caller, by Paul Caton uses assembly language voodoo to enable VB6 to call different types of DLL functions not normally callable from VB6.

The easiest way to make a DLL in C++ and consume it from VB6 is to use COM.

For a regular DLL, you can't use VB references, but rather need to use the Declare statement. Another option would to be create the DLL as an ActiveX component instead.

If it's not a COM library, you need to export only C function with __stdcall. You might need to create .def file for them (http://msdn.microsoft.com/en-us/library/d91k01sh(VS.80).aspx). Also use dependency walker, e.g. depends.exe to see what functions were exported and with which names.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!