|
-
May 3rd, 2002, 06:15 PM
#1
Thread Starter
Hyperactive Member
C++ DLL for VB
I was just wondering how I would go about writing a DLL in C++ for VB6. I know how to make basic DLLs, but I need to be able to do complicated stuff, such as OpenGL API.
-
May 3rd, 2002, 06:52 PM
#2
Junior Member
-
May 4th, 2002, 02:49 PM
#3
PowerPoster
You make a DLL in C++ for VB exactly as you would make a DLL in C++ for anything else. C++ has no idea how you are going to use the DLL and doesn't care. The issue is how do you get VB to get at the functions you put in the DLL, and that's a bit messy.
You have to identify the name of the function in the DLL as it exists after C++ mangles it, and then you have to look up the "alias" statement in VB and figure out how to alias your local VB function name to the mangled C++ (DLL) name.
That's all there is to it. You do, of course, have to be very careful that you pass the right parameters of the right type and in the right order else the alias won't work. An BE CAREFUL about int vs long when talking from VB to C++, and watch out for pass by ref vs pass by val. It is possible to get a valid linkage between VB and the DLL but get weird results if you're not careful.
Have fun
-
May 4th, 2002, 05:08 PM
#4
Monday Morning Lunatic
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
May 5th, 2002, 10:38 AM
#5
The other method, if you want an API that behaves about like the DX8 VB API, is to learn about Automation. It is a weird concept for very advanced programmers that involves a lot of COM, IDispatch and VARIANTs. But it's the only way to get objects from a DLL to any VB version prior to 6.0 (6.0 understands normal COM objects as well, so you could learn those, which is required anyway if you want to learn about automation).
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 6th, 2002, 12:18 PM
#6
New Member
yeah.. unfortunately i haven't figure out how to export classes.
anyone have a clue?
Thanks
-
May 6th, 2002, 12:20 PM
#7
Monday Morning Lunatic
Exporting classes is different to creating a COM DLL, since C++ links to them differently (and a LOT more efficiently, you just don't get some of the distributed benefits though).
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
May 6th, 2002, 12:38 PM
#8
New Member
so would it be possible for me to use a c++ DLL in my VB app?
I've been trying for days without success. Any help would be appreciated.
THANKS!
-
May 6th, 2002, 12:40 PM
#9
Monday Morning Lunatic
Sadly not, C++ DLLs are for C++ only.
If you want to learn about COM, its best to look at the documentation in the Microsoft Platform SDK about COM, and ATL. You have a lot of reading to do
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
May 6th, 2002, 12:56 PM
#10
New Member
actually i meant to type CLASS instead of DLL.
linking c++ dlls to VB is easy.
Public Declare Function TestFunc Lib "testDLL" (byval sSomeVar as string) as Long
where testDLL.dll is in the same folder with a function TestFunc that takes a string as a paramater.. compiled with c++.
and in vb you just
Call TestFunc(sSomeStr)
at any rate.. after exporting functions and classes from c++ DLLs i have only managed to successfully import functions.. not classes.
i've heard it can't be done, but if anyone knows for sure, let me know.
thanks
-
May 6th, 2002, 01:01 PM
#11
Monday Morning Lunatic
That's what I meant.
Normal functions (non-class) can easily be exported because it's just a case of calling a function which VB can do. What VB can't do is to interpret the binary layout of a C++ class, along with all the name mangling that is required.
Either way, you can't use a C++ class from VB unless you're using .NET in which case the whole playing field's been rebuilt
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
May 6th, 2002, 01:29 PM
#12
New Member
word.. .NET ehh? hmm... onwards and upwards i suppose. hehe.
-
May 7th, 2002, 08:46 AM
#13
Actually it is theoretically possible to export classes to VB - just not as classes:
Code:
class ex {
long l1, l2;
void DoSomething();
};
VB Code:
Private Type classex
l1, l2 As Long
End Type
Declare Sub ex_Construct Alias "ex::ex mangled" Lib "whatever.dll" (pThis As classes)
Declare Sub ex_DoSomething Alias "ex::DoSomething mangled" Lib "whatever.dll" (pThis As classex)
Declare Sub ex_Destruct Alias "ex::~ex mangled" Lib "whatever.dll" (pThis As classes)
Should work, because machine code doesn't know classes...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 7th, 2002, 11:25 AM
#14
Monday Morning Lunatic
I think I'll leave you the amusing job of deciphering MS's mangling strategy and writing an auto-converter for VB (templates as well, lets not skimp ).
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
May 10th, 2002, 04:56 AM
#15
Yeah, sure. I already know that C++ mangles always start with ?
I think I'm nearly done.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|