开发者

Calling a Visual Basic DLL in C++, Part 2

This question is a follow up to a previous question (here).

I have acquired a DLL that was created in Visual Basic from a third party vendor(Sensor DLL.dll). This DLL contains functions for talking to a sensor, and I need to call these functions from a Visual C++ program I am writing. The vendor will not provide a header file, and I do not know Visual Basic.

I have a small amount of documentation on each function. For example, I am told one function (Get_Data) in the DLL is of the form:

Public Function Get_Data(ByVal Handle As String) As String

which will return a string with a value between -16777216 and +16777215. That is all.

In the previous question user Hans Passant gave this helpful reply:

A VB6 DLL is normally a COM server. You do in fact have the equivalent of a .h file, it has a type library embedded in it. Start this off with Project + Properties, Common Properties, Framework and References. Add New Reference button, Browse tab, select the DLL.

Next, View + Object Browser. You should see the generated Interop library in the list. Open the node to see what is there. You write normal managed code, like gcnew, to create the COM object and call the interface methods. You do need some minimum documentation on the available methods to have a guess at how they should be called.

Following this advice I did indeed see the list of functions in the DLL in the Object Browser, including Get_Data(System::String) however I am confused about working with COM objects, which is beyond my experience.

I have tried simply call开发者_如何学运维ing Get_Data(Handle); where Handle is a BSTR now that I have added the reference to my project, but it was not recognized. I also tried to call CoInitialize first, but that did not help.

Can anyone tell me specifically what I need to write now to call the function? Thanks!


If I correctly understand your situation, you have at least one COM object implemented in a VB6 .dll. To use this object, you have to create an instance of the COM object before calling the method GetData. CoInitialize will only initialize the COM system. You also have to use an API like CoCreateInstance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜