Hi all,
Ok, so I managed to compile a DLL in C++, and even managed to open it with OpenLibrary() and saw the functions inside using NextLibraryFunction(). Now... how do I call these functions? I noticed that there are some functions for this (CallFunction() and CallCFunction()). However, I have seen some examples here on the forums where people "declare" the import functions in PB code. How does this work? Thanks for any info on this.
Importing my first C++ DLL
Re: Importing my first C++ DLL
You mean something like this?
Code: Select all
;////////////////////////////////////////////////////
; dll only
Prototype _Alert()
Prototype _MsgBox( text.s )
If OpenLibrary( 0, "MyMsgBox.dll" )
Global Alert._Alert = GetFunction( 0, "Alert")
Global MsgBox_._MsgBox = GetFunction( 0, "MsgBox")
EndIf
Procedure MsgBox( text.s="txt" )
ProcedureReturn MsgBox_( text )
EndProcedure
Alert()
MsgBox()
;////////////////////////////////////////////////////
; lib + dll
Import "MyMsgBox.lib"
Alert()
MsgBox( text.s="txt" )
EndImport
Alert()
MsgBox()
Et cetera is my worst enemy
Re: Importing my first C++ DLL
Thanks, I'll try it!
Re: Importing my first C++ DLL
This looks very promissing, but:
If I understand that correctly, this means, the calls would be fast,
but you would require to recompile the calling program,
once the library itself has been (changed and) newly built, right?
This implies, it would be statically linked to the library, doesn't it?help wrote:Once declared, the imported functions are directly available for use in the program, like any other commands. The compiler doesn't check if the functions really exists in the imported file, so if an error occurs, it will be reported by the linker.
If I understand that correctly, this means, the calls would be fast,
but you would require to recompile the calling program,
once the library itself has been (changed and) newly built, right?
Re: Importing my first C++ DLL
You don't have to recompile your program to use a new version of the library,
if the procedures and parameters didn't change that is.
If they changed, then you have to recompile your application,
but you would have to do that anyway, no matter if you use Import or if you load the DLL dynamically.
if the procedures and parameters didn't change that is.
If they changed, then you have to recompile your application,
but you would have to do that anyway, no matter if you use Import or if you load the DLL dynamically.
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
Re: Importing my first C++ DLL
I just tried that with removing an exported procedure before the one, I was importing,Shield wrote:You don't have to recompile your program to use a new version of the library,
if the procedures and parameters didn't change that is.
and yes, it actually continued to work without recompiling the caller.
(The imported procedure was a simple example with a message requester,
the library I built with PB under Linux; using CDECL.)
When I changed the name of the imported procedure in the library,
the caller program ceased to show the message requester of course,
but without any sign of error while being called via click in the gui.
Calling it via commandline, I saw the following output:
This indicates to me, that the linking is aktually done using the name,./TestSo.bin: symbol lookup error: ./TestSo.bin: undefined symbol: InString
not like a (silly) speculation of mine, somehow using an address or possition
inside the library.
As I understand that, there should be at least one lookup
of the name of the called procedure before/while calling it the first time.
Do the subsequent calls to the same procedure also require that lookup
or are those done in a manner like CallCFunctionFast()/CallFunctionFast()?


