Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Wrapping a vb dll or vb.net dll in C++ for use with dbp?

Author
Message
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 9th Dec 2003 19:13
Back a while ago, there was one of the many dll discussions going on and inevitably the topic of vb (activeX) dll's came up and of course the more experienced coders here mentioned that vb dlls can't be used for various reasons. Ok, that's understandable. Then someone mentioned "wrapping" the vb dll in C++ to get it to be usable in dbp. I don't remember who made that comment (I think it was IanM but not sure -sorry if it wasn't you Ian) but I am asking the person who made that statement (or anyone else who knows how) to please elaborate on that. I need some info on how to take a vb6,vb.net dll and use C++ to wrap it up for use with DBP, bear in mind I don't code in C++ at all but I have seen plenty of it and I am sure I could figure out enough (with specific help/tutorials) to do what I want to do. All help is greatly appreciated.

Thanks and happy coding!

-RUST-
TKF15H
21
Years of Service
User Offline
Joined: 20th Jul 2003
Location: Rio de Janeiro
Posted: 9th Dec 2003 19:43
this is something I'd also like to know...

Morfy's Law - Enythink thet ken go rong willll.
Cole's Law - Thinly sliced cabbage.
MushroomHead
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 10th Dec 2003 00:46 Edited at: 11th Dec 2003 14:34
I don't much know about C++ but here is a PowerBasic example and which shows how to call VB6 COM objects (remember to register the dll and make sure VB6 runtines exist on your system) ...

http://homepage.ntlworld.com/ravnit.singh/mess.exe

If you're using VB.NET, it's still possible to use COM Interop with PowerBasic/Delphi but your end user MUST have 30MB of NET framework installed on their machine to work. You setup a standard VB.NET class assembly and code all properties/methods etc then generate the assembly dll. Because this dll is a NET dll, you will need to run a utility :-

tlbexp test.dll /out:test.tlb

or

tlbexp test.dll

This generates portable reference and a VB6 compatible activex dll files which can be used in PowerBasic/Delphi (I believe Delphi can load TLB type files?!?). I guess IanM is the guy to speak to on C++ wrapping.

- Rav.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 10th Dec 2003 04:29
Thank you MushroomHead, i will note what you said.
Yeah I am still waiting for the "heavy hitters" to chime in on this issue (Rich, IanM, TCA, Robk, GuyS...whoops-LOL)

-RUST-

VB.NET makes me all goose-pimply!
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 10th Dec 2003 11:28
I dont touch anything VB related. And haven't done anything .NET related either, so I'll happily pass this onto IanM


Mirrors are more fun than television. Well, that was fun, in a not-so-fun sort of way...
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 10th Dec 2003 20:43
ok, I hear ya, but this is more of a C++ question...
where's IanM?



-RUST-

VB.NET makes me all goose-pimply!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th Dec 2003 01:02
Someone calling?

Yes, you can do this ... I can remember almost everything, except how to create a variant in C++, so the attached code is *almost* ready to run with the DLL that MushroomHead posted the link to.

You create a standard windows DLL (or MFC DLL if you're so inclined) and put the attached code into the .cpp file. You will also need to drop a copy of the MessageBox.dll into the same folder as the source.

It's all commented, so have a ball.


The .NET stuff, I've never had an attempt to import anything except the mscorlib.dll, and that was a console app. I can try it out when I have a few minutes, but that may be some time ...

Plug-ins ... get 'em while they're hot, they're lovely
http://www.matrix1.demon.co.uk
Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 11th Dec 2003 01:06
Well that's some good news for once, thanks a bunch Ian.


"Computers are useless they can only give you answers."
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th Dec 2003 01:10
Well, wouldn't you bloody believe it. 2 minutes after posting the code, I 'remembered' how to build a variant (courtesy of google). Hang on and I'll update the code.

Plug-ins ... get 'em while they're hot, they're lovely
http://www.matrix1.demon.co.uk
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th Dec 2003 01:22
Here it is ... untested still, but it should work Ok.

I didn't need a variant in the end - just a BSTR (windows basic string)

Plug-ins ... get 'em while they're hot, they're lovely
http://www.matrix1.demon.co.uk
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 11th Dec 2003 01:33
Thanks IanM! (and everyone) I will give it a go within the next few days. Swamped with rock-marathon software stuff right now - will be free by monday!

For anyone in the NYC Area - starting monday 15th listen to Q104.3 FM for the annual Rock-and-Roll Charity Marathon (Benefitting Charity Begins At Home) make a donation, get a tshirt or sweat shirt, and there are great raffles and auctions as well - and just know that our software is running the whole show! Meaning the data entry, banking transactions, sql db, reciept generation/fullfillment etc etc! (and it's done in VB6 lol - the dot net kid) We wrote it 3 years ago but the new .NET/ASP.NET version for 2004 is gonna be sick!
Oh yeah we are incorporating soon, and we just got our domain!!!

Sorry for the rambling, but my partner and I are striking out on our own-no more working for the man! And we are happy!!!

Sorry if this ended up in the wrong place!

-RUST-

VB.NET makes me all goose-pimply!
Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 11th Dec 2003 01:47
Hmm... just wondering what or where the 'activextest' header came from? Other then that, it's looking good so far. Thanks.


"Computers are useless they can only give you answers."
Mattman
21
Years of Service
User Offline
Joined: 5th Jun 2003
Location: East Lansing
Posted: 11th Dec 2003 02:26
On the subject of dlls of other languages...

IanM I sent you an e-mail. I would like to know HOW i could use your Visual C++ to DBPro command interface library library and What it can do.

Thanks,
Matt

I am mischeivious
RoooooOoooooKoooooKoooooRoooooOoooooKoooooKooooo!
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 11th Dec 2003 02:52 Edited at: 11th Dec 2003 02:53
IanM,

How would I modify your code to call/use/wrap my dll?

Let's say I have a dll called "DBPTest.dll" with one method in it called "GetNow", and in the dll the vb code was this:

Public Function GetNow() as String
Return Now
End Function

could you show me your code using this simple dll as an example
Thanks

-RUST-

VB.NET makes me all goose-pimply!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th Dec 2003 09:36
Ok, in order of question ...

@Exeat, I gave the project the name activextest, and the project wizard generated most of the rest automatically

@Mattman, It simply allows you to call the DBPro commands directly from your own C++ code, affecting objects, images etc. Download the library and take a little look at the example code included.


@CattleRustler, I'll put together something for you later today, but I need to get a question answered first ... does VB return strings by value or by reference? It's a question of ownership of the string.

If we get this wrong we can a) Crash the app, b) Leak memory

Plug-ins ... get 'em while they're hot, they're lovely
http://www.matrix1.demon.co.uk
MushroomHead
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 11th Dec 2003 11:35
Cool, I too was wondering how to code a variant in C.

- Rav.
Mattman
21
Years of Service
User Offline
Joined: 5th Jun 2003
Location: East Lansing
Posted: 11th Dec 2003 14:18
cool I think that is what I'm, looking for I'll d/l when I get home from school

I am mischeivious
RoooooOoooooKoooooKoooooRoooooOoooooKoooooKooooo!
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 11th Dec 2003 16:20
I am pretty sure that vb returns strings ByValue as default.
Thanks IanM

-RUST-

VB.NET makes me all goose-pimply!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th Dec 2003 20:26 Edited at: 11th Dec 2003 20:27
Something like this - mostly the changes are to convert the BSTR to a standard 8 bit string.

Untested code of course - I don't do VB any more

Plug-ins ... get 'em while they're hot, they're lovely
http://www.matrix1.demon.co.uk
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 11th Dec 2003 20:36
Thank you IanM. In reading your C++ code I get the impression that my test dll will return the GetNow() function as a string in a windows msgbox(). So am I correct to say there is no way of making a generic C++ wrapper for a vb dll? Meaning, if I were to make some large dll's housing many different aspects of wim32 objects I would need to modify the C++ code and handle out the returns?

Maybe I am dreaming but I was looking for a way to write whatever I want as far as a dll in vb then put some generic C++ wrapper on it to use with dbp, without ever having to modify/touch the C++ code, other than maybe changing the name of the dll or function the c++ is pointing to?

Sorry but I am C++ clueless

-RUST-

VB.NET makes me all goose-pimply!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th Dec 2003 23:04
It may be possible to write a generic DLL for VB code, because the VB compiler does this and so does the VC++ compiler, but I don't know how to get that level of access.

Bear in mind that the code is example code, so a lot of the initialisation and shutdown stuff in there would move into separate functions reducing the size of each function, but yes, you would have to write a translation layer around each object member function call that you make, but maybe only if the function uses a variant or a unicode format string. If you avoid variants, and use byte arrays instead of strings you might find it quite easy.

That's pretty much tapped all of my knowledge in this area, because I don't have that much use for this sort of stuff anymore

Plug-ins ... get 'em while they're hot, they're lovely
http://www.matrix1.demon.co.uk
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 12th Dec 2003 18:04
thanks for your help IanM


-RUST-

VB.NET makes me all goose-pimply!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Dec 2003 00:53
Pleasure

Plug-ins ... get 'em while they're hot, they're lovely
http://www.matrix1.demon.co.uk

Login to post a reply

Server time is: 2024-11-24 09:10:29
Your offset time is: 2024-11-24 09:10:29