Including a Dll

Monkey Targets Forums/Desktop/Including a Dll

nigelibrown(Posted 2014) [#1]
I have a desktop project that requires the use of a API dll, I have the header file, the .lib file and the .dll file but keep getting lots of 'not declared in this scope' errors.

I have been able to find some example code on how to use system dll's, but not one you have all the information required to get things going.

I have the same thing working in BlitzMAX without problem using a module. Does anyone have experience of getting this going under Monkey?


dawlane(Posted 2014) [#2]
Have you tried using #CC_OPTS?
The other method is to open up the compiler project file/makefile and add the required libraries directly to the project.


GW_(Posted 2014) [#3]
#CC_OPTS doesn't for the desktop target btw.


DruggedBunny(Posted 2014) [#4]
You'll most likely need to write a wrapper in C++. Not sure if this thread is what you found before, but the example below which resulted from it *might* help you piece together a wrapper:

http://www.hi-toro.com/monkey/dllexample.zip

It was created for the Hardwired 3D library by Ploppy, but it basically shows how to access a plain C DLL from Monkey.

I wrote a program to convert Hardwired's Blitz3D .decls file into C++ declarations (lot of trial and error involved!), so you might want to do something similar for whatever DLL you're trying to use (eg. convert its .h declarations to .cpp and .monkey).

There's a stripped-down version of the hardwiredlib.cpp wrapper in 'stripped.cpp' which may help to separate out the pieces you'll need (opening a DLL, declaring its functions and some function pointers, and so on), along with hardwired.monkey, which demonstrates how to access the C/C++ functions defined in hardwiredlib.cpp (or stripped.cpp) from Monkey.

I'd recommend finding a single function in your DLL (one that produces some kind of observable result) that you can define in .cpp and .monkey form in order to understand and experiment with, then take it from there...