Import 'c' code and linking DLL's

BlitzMax Forums/BlitzMax Beginners Area/Import 'c' code and linking DLL's

RktMan(Posted 2005) [#1]
hi all,

new guy here.

i've seen the docs that talk about how to "import" a 'C' source file to be able to use it's functions.

i haven't tried to actually do this yet, but i didn't even see my scenario mentioned, so I thought I would ask :

i know a bit about how compiling/linking works.

assuming that i have a 'C' source file that I want to "Import" into Blitz.

this 'C' source file is a wrapper that i want to use to glue my blitz application to some code in a DLL i've built from some other code.

how do i get in the middle of the Blitz linker mechanism and get it to link to the DLL ?

mucho,
Tony


BlitzSupport(Posted 2005) [#2]
If it's a DLL, you shouldn't really need to import C code, as you can just call the DLL directly:

' Function declaration...

Global DoIt (x, y)

' Load DLL...

lib = LoadLibraryA ("mylib.dll")

If lib
    ' Assign DLL function to function pointer...
    DoIt = GetProcAddress (lib, "TestFunction")
Else
    Print "Died painfully..."; End
EndIf

Print DoIt (1, 2) ' Calls TestFunction (x, y) from mylib.dll with 1, 2 as parameters


If it's a xxx.a lib, you can just import it, declaring the functions in an Extern/End Extern block.


RktMan(Posted 2005) [#3]
thanks for the followup.

the DLL, in its current form is a 3rd party DLL, is C++ so it isn't extern friendly, and i need to write some 'C' code in any event to bootstrap the stuff in the DLL before i can use it.

but i think you answered my question in a roundabout way in any event.

i think what i need to do is build my wrapper source into the DLL, which will provide the 'extern' API that i need for Blitz, rather than trying to link Blitz and the wrapper to the DLL.

mucho,
Tony


BlitzSupport(Posted 2005) [#4]
Hi Tony, you might also want to take a look at Help -> Language -> Advanced Topics for a little on C/C++ usage.


Mystik(Posted 2005) [#5]
lib = LoadLibraryA ("mylib.dll")


Thats not even recognised in my blitzmax.

Steve.


Mystik(Posted 2005) [#6]
Sorted :)

needed

Import pub.win32

Steve.