How can i run a DLL?
BlitzMax Forums/BlitzMax Beginners Area/How can i run a DLL?
| ||
i spended few days so start DYNAMICALY a user definded DLL but this don't work each time.. download DLL http://www.blitzbase.de/codes.zip source: Local dll :Int =LoadLibraryA("dummy.dll") Local addr:Int =Int(GetProcAddress(dll,"test@8")) Local func:Int (v1:Int, v2:Int) (Int Ptr(Varptr(func)))[0]=addr Print dll +" <dummy.dll" Print addr+" <test@8" Print func(3,4) Print func(3,4) Print func(3,4) Print func(3,4) Print func(3,4) Print func(3,4) Print func(3,4) Print func(3,4) Print func(3,4) Print func(3,4) on my machine - this program display a error message in debugmode after starting few times this function... |
| ||
I got it to work by making a c wrapper, just do something like this in a c file Then do the nessesary externs in bmx , import the c file in bmx.. call the dll init then the wrapper functions ( like GfxInit ). maybe there is another way ? but i couldnt get anything else to work. |
| ||
i don't understand... |
| ||
You just make function pointers in the c file . then make a real function in C that calls the function pointer to the dll .. call the C real function from blitzmax . It does work i been calling my own dll and the freeimage.dll routines no problems at all using it this way. just make your c wrapper file like my post above and Import "mycwrapper.c" then make the externs for the wrapper functions . then just call them from bmax. ( if i get some more time. ill post a more detailed example ) |
| ||
i cannot import source - this are 3rd party dll's or "plugins" with undefined dll-names... but every dll has equal function-names... |
| ||
You dont need the source to the dll ( if thats what u mean ? ). im using a 3rd party dll ( freeimage ). u just make function pointers in your own c file .. setup like in my example above. then make a C function that calls the Function Pointer . then import your c file into bmax and call your C function from bmx ( that calls the function thru the pointers that call the dll functions ) |
| ||
I tried the method MrCredo used to call the GetTickCount function from the win32 API. I didn't give me any errors, even then calling the function 100000 times in a row. Could the problem lie within the dll perhaps? What calling convention does your dll-function use? |
| ||
Ok, your dll use the standard calling convention.(Just checked your sourcecode) Add "win32" to the end of your function declaration. Like this... Local func:Int (v1:Int, v2:Int) "win32" that should take care of the problem. I don't know which calling convention BMax uses by default but by adding "win32" you tell Bmax to use stdcall for this function. Found this interesting article about calling conventions... http://www.angelcode.com/dev/callconv/callconv.html |
| ||
I love you Sweenie... :-) |