Use a C++ DLL

Just starting out? Need help? Post your questions and find answers here.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Use a C++ DLL

Post by Polo »

Hope I'll get more luck with a better topic title!

I'm trying to use a DLL from which I haven't got the source but can't get it to work. It's part of a SDK.
http://www.fileden.com/files/2012/8/19/ ... /smart.zip

Can anyone advise on how to use it? It's ok if I've got to use a wrapper (no idea on how to do it though!), I just need to get that working :)

It's kinda urgent, and keeps me from working on the form designer :cry:
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: Use a C++ DLL

Post by jack »

I am not sure if can or can not use a C++ DLL with PB, here is a small snippet of the exported functions.
Export, SBSDK-vc100-mt-11.0.0.dll
Ordinal Address Name
00000001 10007A2E ??0CEdgeOrientPoints@@QAE@XZ
00000002 100072EC ??0CSBSDK2@@QAE@_N@Z
00000003 1000758A ??0CSBSDK2Advanced@@QAE@PAVCSBSDK2@@@Z
00000004 10007B1F ??0CSBSDK2BoardSettings@@QAE@PAVCSBSDK2@@@Z
00000005 100080D5 ??0CSBSDK2Diag@@QAE@PAVCSBSDK2@@@Z
00000006 1000826C ??0CSBSDK2Test@@QAE@PAVCSBSDK2@@@Z
00000007 10008569 ??0CSBSDK3@@QAE@XZ
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Use a C++ DLL

Post by Polo »

It seems I have to create a wrapper for it, having no skills in C++ that's gonna be a challenge!
User avatar
IceSoft
Addict
Addict
Posts: 1699
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: Use a C++ DLL

Post by IceSoft »

Polo wrote:It seems I have to create a wrapper for it, having no skills in C++ that's gonna be a challenge!
Yes you Need a wrapper, like this one:

Code: Select all

;- - E.S.L (E.S.L.) - -
;- <SBSDK-vc100-mt-11.0.0.lib>4PB.pbi
Macro public:void__thiscallSBSDK_DISPLAY_INFO_W::`defaultructorPointer:i: EndMacro
Macro public:void__thiscallCSBSDK2::`defaultructorPointer:i: EndMacro
Macro UINT:i: EndMacro
Macro public:void__thiscallCSBSDK2Advanced::`defaultructorPointer:i: EndMacro
Macro public:void__thiscallCSBSDK2BoardSettings::`defaultructorPointer:i: EndMacro
Macro public:void__thiscallCSBSDK2Test::`defaultructorPointer:i: EndMacro
Macro public:void__thiscallCSBSDK2Diag::`defaultructorPointer:i: EndMacro
ImportC "D:\Users\peter_000\Desktop\smart\DLL\lib\SBSDK-vc100-mt-11.0.0.lib"
 CEdgeOrientPoints::CEdgeOrientPoints.public:__thiscall() As "??0CEdgeOrientPoints@@QAE@XZ"
 CSBSDK2::CSBSDK2.public:__thiscall(var11.bool) As "??0CSBSDK2@@QAE@_N@Z"
 CSBSDK2Advanced::CSBSDK2Advanced.public:__thiscall(var21.classCSBSDK2) As "??0CSBSDK2Advanced@@QAE@PAVCSBSDK2@@@Z"
 CSBSDK2BoardSettings::CSBSDK2BoardSettings.public:__thiscall(var31.classCSBSDK2) As "??0CSBSDK2BoardSettings@@QAE@PAVCSBSDK2@@@Z"
 CSBSDK2Diag::CSBSDK2Diag.public:__thiscall(var41.classCSBSDK2) As "??0CSBSDK2Diag@@QAE@PAVCSBSDK2@@@Z"
 CSBSDK2Test::CSBSDK2Test.public:__thiscall(var51.classCSBSDK2) As "??0CSBSDK2Test@@QAE@PAVCSBSDK2@@@Z"
 CSBSDK3::CSBSDK3.public:__thiscall() As "??0CSBSDK3@@QAE@XZ"
 CSBSDK3Advanced::CSBSDK3Advanced.public:__thiscall(var71.classCSBSDK3) As "??0CSBSDK3Advanced@@QAE@AAVCSBSDK3@@@Z"
 CSBSDK3BoardSettings::CSBSDK3BoardSettings.public:__thiscall(var81.classCSBSDK3) As "??0CSBSDK3BoardSettings@@QAE@AAVCSBSDK3@@@Z"
 CSBSDK3Diag::CSBSDK3Diag.public:__thiscall(var91.classCSBSDK3) As "??0CSBSDK3Diag@@QAE@AAVCSBSDK3@@@Z"
 CSBSDK3Test::CSBSDK3Test.public:__thiscall(var101.classCSBSDK3) As "??0CSBSDK3Test@@QAE@AAVCSBSDK3@@@Z"
 CSBSDK::CSBSDK.Protected:__thiscall() As "??0CSBSDK@@IAE@XZ"
 CSBSDKCameraTarget::CSBSDKCameraTarget.public:__thiscall(var121.i,var122.float,var123.float,var124.i) As "??0CSBSDKCameraTarget@@QAE@HMMH@Z"
 CSBSDKCameraTarget::CSBSDKCameraTarget.public:__thiscall() As "??0CSBSDKCameraTarget@@QAE@XZ"
 CSBSDKCameraTargetList::CSBSDKCameraTargetList.public:__thiscall(var141.classCSBSDKCameraTargetList) As "??0CSBSDKCameraTargetList@@QAE@ABV0@@Z"
 CSBSDKCameraTargetList::CSBSDKCameraTargetList.public:__thiscall() As "??0CSBSDKCameraTargetList@@QAE@XZ"
 CSBSDKContact::CSBSDKContact.public:__thiscall(var161.classCSBSDKWnd,var162.enumSBSDK_CONTACT_STATE,var163.long,var164.i,var165.float,var166.float,var167.float,var168.float,var169.float,var1610.float,var1611.float,var1612.float,var1613.float,var1614.float) As "??0CSBSDKContact@@QAE@VCSBSDKWnd@@W4SBSDK_CONTACT_STATE@@KHMMMMMMMMMM@Z"
 CSBSDKContact::CSBSDKContact.public:__thiscall() As "??0CSBSDKContact@@QAE@XZ"
 CSBSDKContactList::CSBSDKContactList.private:__thiscall(var181.classCSBSDKContactList) As "??0CSBSDKContactList@@AAE@AAV0@@Z"
 CSBSDKContactList::CSBSDKContactList.public:__thiscall() As "??0CSBSDKContactList@@QAE@XZ"
 CSBSDKEX::CSBSDKEX.public:__thiscall() As "??0CSBSDKEX@@QAE@XZ"
 CSBSDKServer::CSBSDKServer.Protected:__thiscall() As "??0CSBSDKServer@@IAE@XZ"
 CSBSDKWnd::CSBSDKWnd.public:__thiscall(*var221.HWND__) As "??0CSBSDKWnd@@QAE@PAUHWND__@@@Z"
 CSBSDKWnd::CSBSDKWnd.public:__thiscall() As "??0CSBSDKWnd@@QAE@XZ"
 CSBSDKWndList::CSBSDKWndList.private:__thiscall(var241.classCSBSDKWndList) As "??0CSBSDKWndList@@AAE@AAV0@@Z"
 CSBSDKWndList::CSBSDKWndList.public:__thiscall() As "??0CSBSDKWndList@@QAE@XZ"
 SBSDK_DISPLAY_INFO_W::SBSDK_DISPLAY_INFO_W.public:__thiscall(var261.i,var262.i,var263.i,var264.i,var265.i,var266.i,var267.,var268.i,var269.i,*var2610.tagSBSDK_ORIENT_PTS) As "??0SBSDK_DISPLAY_INFO_W@@QAE@ABH00000QBG00PBUtagSBSDK_ORIENT_PTS@@@Z"
 SBSDK_DISPLAY_INFO_W::SBSDK_DISPLAY_INFO_W.public:__thiscall(var271.classSBSDK_DISPLAY_INFO_W) As "??0SBSDK_DISPLAY_INFO_W@@QAE@ABV0@@Z"
 SBSDK_DISPLAY_INFO_W::SBSDK_DISPLAY_INFO_W.public:__thiscall(var281.i,var282.i) As "??0SBSDK_DISPLAY_INFO_W@@QAE@HH@Z"
 CEdgeOrientPoints::~CEdgeOrientPoints.public:__thiscall() As "??1CEdgeOrientPoints@@QAE@XZ"
 CSBSDK2::~CSBSDK2.public:virtual__thiscall() As "??1CSBSDK2@@UAE@XZ"
 CSBSDK2Advanced::~CSBSDK2Advanced.public:virtual__thiscall() As "??1CSBSDK2Advanced@@UAE@XZ"
 CSBSDK2AdvancedEventHandler::~CSBSDK2AdvancedEventHandler.public:virtual__thiscall() As "??1CSBSDK2AdvancedEventHandler@@UAE@XZ"
 CSBSDK2BoardSettings::~CSBSDK2BoardSettings.public:virtual__thiscall() As "??1CSBSDK2BoardSettings@@UAE@XZ"
 CSBSDK2BoardSettingsEventHandler::~CSBSDK2BoardSettingsEventHandler.public:virtual__thiscall() As "??1CSBSDK2BoardSettingsEventHandler@@UAE@XZ"
 CSBSDK2Diag::~CSBSDK2Diag.public:virtual__thiscall() As "??1CSBSDK2Diag@@UAE@XZ"
 CSBSDK2DiagEventHandler::~CSBSDK2DiagEventHandler.public:virtual__thiscall() As "??1CSBSDK2DiagEventHandler@@UAE@XZ"
 CSBSDK2EventHandler::~CSBSDK2EventHandler.public:virtual__thiscall() As "??1CSBSDK2EventHandler@@UAE@XZ"
 CSBSDK2Test::~CSBSDK2Test.public:virtual__thiscall() As "??1CSBSDK2Test@@UAE@XZ"
 CSBSDK2TestEventHandler::~CSBSDK2TestEventHandler.public:virtual__thiscall() As "??1CSBSDK2TestEventHandler@@UAE@XZ"
 CSBSDK3::~CSBSDK3.public:virtual__thiscall() As "??1CSBSDK3@@UAE@XZ"
 CSBSDK3Advanced::~CSBSDK3Advanced.public:virtual__thiscall() As "??1CSBSDK3Advanced@@UAE@XZ"
 CSBSDK3AdvancedEventHandler::~CSBSDK3AdvancedEventHandler.public:virtual__thiscall() As "??1CSBSDK3AdvancedEventHandler@@UAE@XZ"
 CSBSDK3BoardSettings::~CSBSDK3BoardSettings.public:virtual__thiscall() As "??1CSBSDK3BoardSettings@@UAE@XZ"
 CSBSDK3BoardSettingsEventHandler::~CSBSDK3BoardSettingsEventHandler.public:virtual__thiscall() As "??1CSBSDK3BoardSettingsEventHandler@@UAE@XZ"
 CSBSDK3Diag::~CSBSDK3Diag.public:virtual__thiscall() As "??1CSBSDK3Diag@@UAE@XZ"
 CSBSDK3DiagEventHandler::~CSBSDK3DiagEventHandler.public:virtual__thiscall() As "??1CSBSDK3DiagEventHandler@@UAE@XZ"
 CSBSDK3EventHandler::~CSBSDK3EventHandler.public:virtual__thiscall() As "??1CSBSDK3EventHandler@@UAE@XZ"
 CSBSDK3MessageReceivedEventHandler::~CSBSDK3MessageReceivedEventHandler.public:virtual__thiscall() As "??1CSBSDK3MessageReceivedEventHandler@@UAE@XZ"
 CSBSDK3Test::~CSBSDK3Test.public:virtual__thiscall() As "??1CSBSDK3Test@@UAE@XZ"
 CSBSDK3TestEventHandler::~CSBSDK3TestEventHandler.public:virtual__thiscall() As "??1CSBSDK3TestEventHandler@@UAE@XZ"
 CSBSDK::~CSBSDK.public:virtual__thiscall() As "??1CSBSDK@@UAE@XZ"
 CSBSDKCameraTarget::~CSBSDKCameraTarget.public:virtual__thiscall() As "??1CSBSDKCameraTarget@@UAE@XZ"
 CSBSDKCameraTargetList::~CSBSDKCameraTargetList.public:virtual__thiscall() As "??1CSBSDKCameraTargetList@@UAE@XZ"
 CSBSDKContact::~CSBSDKContact.public:virtual__thiscall() As "??1CSBSDKContact@@UAE@XZ"
 CSBSDKContactList::~CSBSDKContactList.public:virtual__thiscall() As "??1CSBSDKContactList@@UAE@XZ"
 CSBSDKEX::~CSBSDKEX.public:virtual__thiscall() As "??1CSBSDKEX@@UAE@XZ"
 CSBSDKServer::~CSBSDKServer.public:virtual__thiscall() As "??1CSBSDKServer@@UAE@XZ"
 CSBSDKWnd::~CSBSDKWnd.public:__thiscall() As "??1CSBSDKWnd@@QAE@XZ"
 CSBSDKWndList::~CSBSDKWndList.public:virtual__thiscall() As "??1CSBSDKWndList@@UAE@XZ"
 CSBSDKCameraTargetList::operator=.public:classCSBSDKCameraTargetList__thiscall(var601.classCSBSDKCameraTargetList) As "??4CSBSDKCameraTargetList@@QAEAAV0@ABV0@@Z"
 CSBSDKContactList::operator=.public:classCSBSDKContactList__thiscall(var611.classCSBSDKContactList) As "??4CSBSDKContactList@@QAEAAV0@AAV0@@Z"
 CSBSDKWndList::operator=.public:classCSBSDKWndList__thiscall(var621.classCSBSDKWndList) As "??4CSBSDKWndList@@QAEAAV0@AAV0@@Z"
 SBSDK_DISPLAY_INFO_W::operator=.public:classSBSDK_DISPLAY_INFO_W__thiscall(var631.classSBSDK_DISPLAY_INFO_W) As "??4SBSDK_DISPLAY_INFO_W@@QAEAAV0@ABV0@@Z"
 CSBSDKWnd::operator==.public:int__thiscall(var641.classCSBSDKWnd) As "??8CSBSDKWnd@@QAEHAAV0@@Z"
 CSBSDKWnd::operator!=.public:int__thiscall(var651.classCSBSDKWnd) As "??9CSBSDKWnd@@QAEHAAV0@@Z"
 closure'.public:void__thiscallCSBSDK2::`defaultructorPointer() As "??_FCSBSDK2@@QAEXXZ"
 closure'.public:void__thiscallCSBSDK2Advanced::`defaultructorPointer() As "??_FCSBSDK2Advanced@@QAEXXZ"
 closure'.public:void__thiscallCSBSDK2BoardSettings::`defaultructorPointer() As "??_FCSBSDK2BoardSettings@@QAEXXZ"
 closure'.public:void__thiscallCSBSDK2Diag::`defaultructorPointer() As "??_FCSBSDK2Diag@@QAEXXZ"
 closure'.public:void__thiscallCSBSDK2Test::`defaultructorPointer() As "??_FCSBSDK2Test@@QAEXXZ"
 closure'.public:void__thiscallSBSDK_DISPLAY_INFO_W::`defaultructorPointer() As "??_FSBSDK_DISPLAY_INFO_W@@QAEXXZ"
 SBSDKStringCopyA.c(var721.c,var722.c) As "?SBSDKStringCopyA@@YAPADPADPBD@Z"
 SBSDKStringCopyW.short(var731.short,var732.short) As "?SBSDKStringCopyW@@YAPAGPAGPBG@Z"
 SBSDKStringLenA.UINT(var741.c) As "?SBSDKStringLenA@@YAIPBD@Z"
 SBSDKStringLenW.UINT(var751.short) As "?SBSDKStringLenW@@YAIPBG@Z"
EndImport
Belive! C++ version of Puzzle of Mystralia
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Use a C++ DLL

Post by Polo »

Thanks, that doesn't compile though, gives a macro error?
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Use a C++ DLL

Post by Shield »

Because it is pure nonsense.

Polo, you need to create a wrapper for each method to solve the name mangling issues.
You also need to write additional Create / Destroy functions for each class to be able to create
objects properly in PB.

It might be also possible to use interfaces (via virtual methods in C++), but that is a lot
more difficult and it's very annoying to get it straight (tried it before).

Best is you write one function for each method and ignore modules.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
IceSoft
Addict
Addict
Posts: 1699
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: Use a C++ DLL

Post by IceSoft »

Shield wrote:Because it is pure nonsense.

Polo, you need to create a wrapper for each method to solve the name mangling issues.
You also need to write additional Create / Destroy functions for each class to be able to create
objects properly in PB.

It might be also possible to use interfaces (via virtual methods in C++), but that is a lot
more difficult and it's very annoying to get it straight (tried it before).

Best is you write one function for each method and ignore modules.
Right! But it was not 'pure nonsense' it is what E.S.L. (Examine Static Library) can detect from this nativ library.
Writting a wrapper is not realy so hard it is more a "Just Do It!" job which is not realy valuable if it is used only from one 'user'.
Or in short words: To much work for only one 'user'.
Belive! C++ version of Puzzle of Mystralia
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Use a C++ DLL

Post by Polo »

IceSoft wrote:Writting a wrapper is not realy so hard it is more a "Just Do It!" job
It is hard when you've got no idea how to do this :)
User avatar
IceSoft
Addict
Addict
Posts: 1699
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: Use a C++ DLL

Post by IceSoft »

Polo wrote:
IceSoft wrote:Writting a wrapper is not realy so hard it is more a "Just Do It!" job
It is hard when you've got no idea how to do this :)
PB cannot handle OOP designed DLLs without a C style like wrapper.
So that's the best answer for writting a wrapper from an OOP designed DLL:
Shield wrote: Best is you write one function for each method and ignore modules.
Last edited by IceSoft on Sat Feb 16, 2013 3:09 pm, edited 1 time in total.
Belive! C++ version of Puzzle of Mystralia
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Use a C++ DLL

Post by Shield »

Polo wrote:It is hard when you've got no idea how to do this :)
I guess so since you mentioned you don't know C++.

Unfortunately I can't give you a good example code at this time, but there are
several examples floating around here and on the German forums.

To start with you can try to compile a DLL in C++ (shouldn't be too hard, there are lots of examples)
and create custom functions (simple AddTest(a, b)) which you export and then import in PB.

Once you managed to do that you basically just need to create a wrapper function for each method of each class
(including constructors and destructors). After you figured out how to export functions in C++ (maybe someone can give you an example),
it won't be too difficult to create the wrapper because it's the same procedure over and over again. :)

I guess this post wasn't too helpful, sorry.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Use a C++ DLL

Post by Polo »

I managed creating a function in C and using it in Purebasic, but I didn't manage to actually use the functions from the other DLL as I've got no idea on how to do this, starting from linking the dll in my own dll :oops:
User avatar
idle
Always Here
Always Here
Posts: 6108
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Use a C++ DLL

Post by idle »

Polo you should be able to use the comwrapper in the \c++ VB c# dir of the sdk
by porting the idl file in the \include dir
Windows 11, Manjaro, Raspberry Pi OS
Image
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Use a C++ DLL

Post by Polo »

idle wrote:Polo you should be able to use the comwrapper in the \c++ VB c# dir of the sdk
by porting the idl file in the \include dir
Thanks for your answer idle - do you know how to do that?
From previous answers I had the feeling that to use that com wrapper I had to do some registry setting (which I want to avoid)?
User avatar
idle
Always Here
Always Here
Posts: 6108
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Use a C++ DLL

Post by idle »

I don't know and simply can't remember if you need to register or not.
As for doing it, I think I remember seeing a com tutorial from Freak
The com wrapper would likely be the easiest way of tackling it and is compatible with interfaces
Windows 11, Manjaro, Raspberry Pi OS
Image
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Use a C++ DLL

Post by Polo »

I've seen the tutorial, seems I have to "register" that com thing. And I must say I still don't have a clue where to start.
Can't believe I spent so much time trying to do something very simple in the end, with absolutely no result yet :|
Some SDKs are just so badly designed...
Post Reply