Author |
Message |
Chris Fran #1 / 11
|
 Calling a function in a C++ Win32 Dll from VB 6
I am trying to write a Win32 DLL using Visual C++. Whenever I try to call a function from VB 6 I get an "Entry point not found" error. I can call the function from C++ with no problems. Is there a way to write a Win32 DLL that VB can access or do I have to Write an ATL COM object? Any sample code would be very helpful. Thanks Chris
|
Fri, 13 Dec 2002 03:00:00 GMT |
|
 |
Jonathan Woo #2 / 11
|
 Calling a function in a C++ Win32 Dll from VB 6
You need to create a DEF file that includes all your exports. However, if this is C++ code and not C, then you need to deal with the issue of name mangling, which C++ implements to keep overloaded function names unique. -- Jonathan Wood SoftCircuits Programming http://www.softcircuits.com
Quote: > I am trying to write a Win32 DLL using Visual C++. Whenever I try to call a > function from VB 6 I get an "Entry point not found" error. > I can call the function from C++ with no problems. Is there a way to write > a Win32 DLL that VB can access or do I have to Write an ATL COM object? > Any sample code would be very helpful. > Thanks > Chris
|
Fri, 13 Dec 2002 03:00:00 GMT |
|
 |
Ray Merce #3 / 11
|
 Calling a function in a C++ Win32 Dll from VB 6
The DEF file *is* how you deal with name mangling. There is an example C-DLL and VB project called RoundMe in my code sample section: Hope this helps, Ray Mercer www.shrinkwrapvb.com
Quote: > You need to create a DEF file that includes all your exports. > However, if this is C++ code and not C, then you need to deal with the issue > of name mangling, which C++ implements to keep overloaded function names > unique. > -- > Jonathan Wood > SoftCircuits Programming > http://www.softcircuits.com
> > I am trying to write a Win32 DLL using Visual C++. Whenever I try to call > a > > function from VB 6 I get an "Entry point not found" error. > > I can call the function from C++ with no problems. Is there a way to > write > > a Win32 DLL that VB can access or do I have to Write an ATL COM object? > > Any sample code would be very helpful. > > Thanks > > Chris
|
Sat, 14 Dec 2002 03:00:00 GMT |
|
 |
Chris Fran #4 / 11
|
 Calling a function in a C++ Win32 Dll from VB 6
Thanks! I got it to work. Now on to the hard stuff.
Quote: > The DEF file *is* how you deal with name mangling. > There is an example C-DLL and VB project called RoundMe in my code sample > section: > Hope this helps, > Ray Mercer > www.shrinkwrapvb.com
> > You need to create a DEF file that includes all your exports. > > However, if this is C++ code and not C, then you need to deal with the > issue > > of name mangling, which C++ implements to keep overloaded function names > > unique. > > -- > > Jonathan Wood > > SoftCircuits Programming > > http://www.softcircuits.com
> > > I am trying to write a Win32 DLL using Visual C++. Whenever I try to > call > > a > > > function from VB 6 I get an "Entry point not found" error. > > > I can call the function from C++ with no problems. Is there a way to > > write > > > a Win32 DLL that VB can access or do I have to Write an ATL COM object? > > > Any sample code would be very helpful. > > > Thanks > > > Chris
|
Sat, 14 Dec 2002 03:00:00 GMT |
|
 |
Jonathan Woo #5 / 11
|
 Calling a function in a C++ Win32 Dll from VB 6
Ray, Quote: > The DEF file *is* how you deal with name mangling.
Huh? Since I write my DLLs in C or assembler, I do in fact use a .DEF file to deal with the underscore, etc. normally prepended to function names. However, real C++ name mangling (the type used to keep overloaded function named unique) cannot be resolved with a .DEF file. I brought that up because it was not clear to me if the original poster was writing the DLL in C++. -- Jonathan Wood SoftCircuits Programming http://www.softcircuits.com
Quote: > The DEF file *is* how you deal with name mangling. > There is an example C-DLL and VB project called RoundMe in my code sample > section: > Hope this helps, > Ray Mercer > www.shrinkwrapvb.com
> > You need to create a DEF file that includes all your exports. > > However, if this is C++ code and not C, then you need to deal with the > issue > > of name mangling, which C++ implements to keep overloaded function names > > unique. > > -- > > Jonathan Wood > > SoftCircuits Programming > > http://www.softcircuits.com
> > > I am trying to write a Win32 DLL using Visual C++. Whenever I try to > call > > a > > > function from VB 6 I get an "Entry point not found" error. > > > I can call the function from C++ with no problems. Is there a way to > > write > > > a Win32 DLL that VB can access or do I have to Write an ATL COM object? > > > Any sample code would be very helpful. > > > Thanks > > > Chris
|
Sat, 14 Dec 2002 03:00:00 GMT |
|
 |
Mattias Sj?gr #6 / 11
|
 Calling a function in a C++ Win32 Dll from VB 6
Jonathan & Ray, Quote: >Since I write my DLLs in C or assembler, I do in fact use a .DEF file to >deal with the underscore, etc. normally prepended to function names. >However, real C++ name mangling (the type used to keep overloaded function >named unique) cannot be resolved with a .DEF file. I brought that up because >it was not clear to me if the original poster was writing the DLL in C++.
Correct me if I'm wrong, but I don't think C vs. C++ matters here. It's the calling convention that does it, isn't it? _stdcall functions get the name
And that can be "unmangled" by a DEF file. Whether or not it works for other calling conventions seems irrelevant in this case, since VB only supports _stdcall. Mattias ____________________________________________
|
Sat, 14 Dec 2002 03:00:00 GMT |
|
 |
Jonathan Woo #7 / 11
|
 Calling a function in a C++ Win32 Dll from VB 6
Mattias, Quote: > Correct me if I'm wrong, but I don't think C vs. C++ matters here. > It's the calling convention that does it, isn't it? _stdcall functions > get the name
> And that can be "unmangled" by a DEF file. Whether or not it works for > other calling conventions seems irrelevant in this case, since VB only > supports _stdcall.
True C++ functions employ their own name mangling. How do you suppose the linker resolves overloaded functions? int myfunc(char *p); int myfunc(int i); .DEF files have no say over this unless someone knows something I don't here. -- Jonathan Wood SoftCircuits Programming http://www.softcircuits.com
|
Sat, 14 Dec 2002 03:00:00 GMT |
|
 |
Mattias Sj?gr #8 / 11
|
 Calling a function in a C++ Win32 Dll from VB 6
Hi Jonathan, Quote: >True C++ functions employ their own name mangling. How do you suppose the >linker resolves overloaded functions?
Darn.. yes, of course you're right. Sorry you had to write that three times for me to believe it :-) Back to your previous post then: Quote: >However, real C++ name mangling (the type used to keep overloaded function >named unique) cannot be resolved with a .DEF file.
That's not completely true however. And this time I'm pretty sure, because I just tried it :-) It requires a bit more work, and of course you can't export the functions with the same name, but it *is* possible. First export them using _declspec(dllexport). Use Dependency Walker, Dumpbin or similar tool to get the decorated name. Put it in the DEF file, remove the _declspec(dllexport) statements and rebuild. Here's what I tested with: --- CPP file --- int _stdcall func1(char* s) { /* ... */ } int _stdcall func1(int i) { /* ... */ } --- DEF file --- EXPORTS
Mattias ____________________________________________
|
Sat, 14 Dec 2002 03:00:00 GMT |
|
 |
Jonathan Woo #9 / 11
|
 Calling a function in a C++ Win32 Dll from VB 6
Mattias, Quote: > EXPORTS
Yep, that's what I was looking for. Hadn't tried that since I have never used C++ to write DLL libraries to be called from VB. However, I still consider it a bit of a pain, if you ask me, to find what the mangled names are, and that they can change if you compile with a different C++ compiler. -- Jonathan Wood SoftCircuits Programming http://www.softcircuits.com
|
Sat, 14 Dec 2002 03:00:00 GMT |
|
 |
Berger, Kristo #10 / 11
|
 Calling a function in a C++ Win32 Dll from VB 6
Hi! Use stdcall calling-convention. Cheers Kristof Quote: -----Original Message-----
Posted At: Dienstag, 27. Juni 2000 02:49 Posted To: winapi Conversation: Calling a function in a C++ Win32 Dll from VB 6 Subject: Re: Calling a function in a C++ Win32 Dll from VB 6 You need to create a DEF file that includes all your exports. However, if this is C++ code and not C, then you need to deal with the issue of name mangling, which C++ implements to keep overloaded function names unique. -- Jonathan Wood SoftCircuits Programming http://www.softcircuits.com
> I am trying to write a Win32 DLL using Visual C++. Whenever I try to call a > function from VB 6 I get an "Entry point not found" error. > I can call the function from C++ with no problems. Is there a way to write > a Win32 DLL that VB can access or do I have to Write an ATL COM object? > Any sample code would be very helpful. > Thanks > Chris
|
Sat, 14 Dec 2002 03:00:00 GMT |
|
 |
Ray Merce #11 / 11
|
 Calling a function in a C++ Win32 Dll from VB 6
Hi Jonathon, Quote: > > The DEF file *is* how you deal with name mangling. > Huh? > Since I write my DLLs in C or assembler, I do in fact use a .DEF file to > deal with the underscore, etc. normally prepended to function names. > However, real C++ name mangling (the type used to keep overloaded function > named unique) cannot be resolved with a .DEF file. I brought that up because > it was not clear to me if the original poster was writing the DLL in C++.
This is only an issue if the DLL uses overloaded functions, which the poster made no mention of. As Mattias pointed out you can get around even those with a DEF file, but for the vast majority of C++ DLLs all you need is this: EXPORTS FunctionName The linker is smart enough to export the function with that name just as it is in either C or C++, no need for extern C or anything. The MSVC docs don't explain this well however and even hint that DEF files are no longer necessary. However, I have found that they make life *much* easier when writing DLLs for VB (of course it's not necessary if you are writing the DLL for C++ use). If you want to add some options: LIBRARY DLLName DESCRIPTION "Cool function library by Joe Blow" EXPORTS FunctionOne FunctionTwo e.g., [Private] Declare Function FunctionOne Lib "DLLName" (ByVal inPut as Long) as Long Ray Mercer MS-MVP Visual Basic www.shrinkwrapvb.com
|
Mon, 16 Dec 2002 03:00:00 GMT |
|
|