Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C++ declarations in VB 1

Status
Not open for further replies.

irocz

IS-IT--Management
Oct 28, 2001
25
US
Hi,
Has anybody ever converted c++ declaration to a VB program, I looked at the help within the DLL section and did not provide much.
Thanks
 
It is not clear what you are asking.

Porting C++ code to v.b. or calling a dll written in C++ from VB?

If it is the latter- there have been 3 or 4 posts in the last few weeks that might be helpful- I could try and dig them up if that is what you need.

If it is the former- well that's a bit of a longish answer as it basically implies the need to understand both languages.

 
Thanks for your response, and sorry I was not so clear. Here it is:
I have a dll which was writen in c++ which I want to use in my VB programs, since I am not a c++ programmer and already have a lot invested in VB. My major problem is the declarations in the include file(s) for using that dll, such as a reference to a class or to a void definition.
Thanks
 
Using DLL's from Visual Basic requires some level of expertise. It is too broad a topic to give you a definitive answer here. I recommend that you get Dan Appleman's "Visual Basic X Programmer's Guide to Win32 API." The reason for the "X" is that Dan has written this guide for the VB 4, 5, and 6. Any one of these books will help.

Don't let the fact that the title cites the Win32 API throw you. The fact is that the Windows API is simply a collection of C and C++ DLL's. Dan goes into some detail on translations of the C interface from a VB perspective. There are some real pitfalls and the Microsoft documentation on the subject is fraught with errors. Dan corrects them.

When I got confused with a few things, I called his company and Dan actually helped me out. It's a small company and Dan really does like helping people, especially the ones who buy his books. It's even better if you like his jokes. :)
 
Thank you for your response. I actually have the book by Dan Appleman, but nowhere did I see what I was looking for.
I even looked at the example he supplied APIGID32.DLL, and it does not provide me with what I want.
Here is the scenario.
The DLL was written in C++, I can use that DLL in VC, because the include file (hpp) defines the class and the object for that class, i.e. class::eek:b, this in fact is what I would like to use in the VB environment.
Thanks
 
sorry about the delay irocz- I was gone for the week end.

In order to access a method in the DLL - the DLL must export the method. VC++ does this w/a DEF file that will have something like this in it:

Code:
LIBRARY myc.dll

EXPORTS
     mymethod

When the DLL is compiled and you have the method you want to use exported then you declare that method in VB the same way you declare an API call.

It's really not that complicated- though passing some types of data can be a pain- like strings. There are some good threads on this board though w/links to helpful pages on that topic.

hope that helps,
Ron
 
Hi Ron,
Thank you for your response.
In my C++ DLL, I have the correct code I think, I have the __stdcall, and the __declspec(dllexport), and I know about the alternative of defining the EXPORTS in the .DEF file, but the code is already developed.
I declare the function(s) in my VB program without the "ALIAS", first because I honestly cannot determine what the alias name should be if not the same as the function name, second because I know that C++ mangles the names. I tried to use the suffix "A" and the suffix "W", I still get the same error when I call the function, which is: "can't find entry point in dll".So, I do not know whether it is a whitespace problem or something else.
Just to give you some more details, in my header file(hpp), I define a class with many methods(functions) within that class. When I call the function within the DLL from VC it works with no problem (my call is class:function), which I cannot do in VB, the declare statement won't allow it.
Thanks for your help, I will try to look for those threads you mentioned.
Regards,
Eddie
 
irocz,

You can use DUMPBIN /EXPORTS to show you the "mangled" names. Even C mangles names when you select the parameter passing options (eg. __stdcall, _cdecl, etc.).

That said, use the values from DUMPBIN as the alias field.

Alias "_fnLogErrorMsg@12" is really a function declared in C++ as

extern "C" __declspec(dllexport) long __stdcall fnLogErrorMsg( char * pszLogFileName, char * pszErrorMsg, long errNo );

AND compiled as an export.

The A and W extensions you are talking about refer to ANSI and UNICODE character sets and are relevant to the Win32 APIs.
 
avanderlaan,
That was an excellent tip, ran the dumpbin and found the mangled names... it is working now.
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top