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.

DLL Talk / Using a PureBasic DLL in VS

Author
Message
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 5th Aug 2006 14:02 Edited at: 5th Aug 2006 14:02
I'm trying to get a PureBasic imported into VS, but at the moment it keeps saying the function cant be found.

I've tried using #pragma comment and __declspec(dllimport), but nothing seems to work, and, of course, putting the .LIB file into the workspace.

Come to the last Unofficial DBPro Convention (http://convention.logicstudios.net/)
Supplying "NO" since 1974...
Freddix
AGK Developer
22
Years of Service
User Offline
Joined: 19th Sep 2002
Location: France
Posted: 5th Aug 2006 22:51
which version of Pure do you use ? 4.0 ?
don't forget that pure use undecorated functions form...

All we have to decide is what to do with the time that is given to us.
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 6th Aug 2006 00:39
4.0

Using __declspec(dllimport) should do it, but unfortunately it doesn't

Come to the last Unofficial DBPro Convention (http://convention.logicstudios.net/)
Supplying "NO" since 1974...
Freddix
AGK Developer
22
Years of Service
User Offline
Joined: 19th Sep 2002
Location: France
Posted: 6th Aug 2006 01:41 Edited at: 6th Aug 2006 01:42
in your PureBASIC DLL, do you use :

Procedure MyProcedure( ... ) ?
or
ProcedureCDLL MyProcedure( ... ) ?

Procedure MyProcedure(...):
Is local to the DLL and can't be reached from another DLL

ProcedureDLL MyProcedure(...)
& ProcedureCDLL MyProcedure(...) :
Are global and can't be called from another DLL.

your problem maybe came from here ?
Otherwise, try to give more informations (error message, how it react...)

All we have to decide is what to do with the time that is given to us.
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 6th Aug 2006 01:47 Edited at: 6th Aug 2006 01:48
PB Code :



VS Code (with TestDLL.lib added to the workspace) :



And the message I get is :

estDarkSDK.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl _openConsole(void)" (__imp_?_openConsole@@YAXXZ)

Come to the last Unofficial DBPro Convention (http://convention.logicstudios.net/)
Supplying "NO" since 1974...
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 6th Aug 2006 03:29
From the error message it seems to expect a decorated function name. Prolly put an extern "C" in front of your prototyped function (not that I know a lot about VS)?


Play Nice! Play Basic! -- Styx PlugIn- Coming Soon!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 6th Aug 2006 12:05
Nick, post up a PB DLL that does something like messagebox and we can play around with it.

OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 6th Aug 2006 12:08
This is the PB stuff

Come to the last Unofficial DBPro Convention (http://convention.logicstudios.net/)
Supplying "NO" since 1974...

Attachments

Login to view attachments
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 6th Aug 2006 12:10 Edited at: 6th Aug 2006 12:17
And this is the VS project.

Quote: "Prolly put an extern "C" in front of your prototyped function (not that I know a lot about VS)?"

No, wont work - its a C function (and code), not C++

I must admit, I'm at a loss - Depends sees the DLL as _openConsole, so it should be usable.

Come to the last Unofficial DBPro Convention (http://convention.logicstudios.net/)
Supplying "NO" since 1974...

Attachments

Login to view attachments
Freddix
AGK Developer
22
Years of Service
User Offline
Joined: 19th Sep 2002
Location: France
Posted: 6th Aug 2006 12:40
what I suggest you, is to name your procedure in PB this way :
ProcedureDLL Z_openConsoleZZYAXXZ()
Once you've compiled your DLL use a small program like XVI32 (Hex editor)
and replace the Z_openConsoleZZYAXXZ with ?Z_openConsole@@YAXXZ
it may then work in VS

All we have to decide is what to do with the time that is given to us.
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 6th Aug 2006 13:38 Edited at: 6th Aug 2006 13:43
Sounds like a bit of work... Would be easier to load the DLL and use GetProcAddress...

Come to the last Unofficial DBPro Convention (http://convention.logicstudios.net/)
Supplying "NO" since 1974...
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 6th Aug 2006 14:21
And no nicking the code I'm doing a plug-in..;

Come to the last Unofficial DBPro Convention (http://convention.logicstudios.net/)
Supplying "NO" since 1974...
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 6th Aug 2006 19:14
PB Code, make sure to include a leading underscore on the names you want to export, as per the _openConsole code in your PB example.

CPP code ... well, it's easier to show you:


It links OK, but doesn't do much when it runs (obviously!) - but most importantly, it doesn't crash.

You need to experiment by passing variables to/from the exported code, make sure you use the cdecl convention on each side ... basically test the hell out of it.

OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 6th Aug 2006 19:19
I'll try that later - thanks.

Come to the last Unofficial DBPro Convention (http://convention.logicstudios.net/)
Supplying "NO" since 1974...

Login to post a reply

Server time is: 2024-11-22 12:09:59
Your offset time is: 2024-11-22 12:09:59