Calling a function returning a string (in dll)
BlitzMax Forums/BlitzMax Programming/Calling a function returning a string (in dll)
| ||
I would like to call a function inside a dll, this function returning a string. Here is how I am doing this in a short example:Const DllName:String = "mydll.dll" Local DllHandle = LoadLibraryA(DllName) If DLLhandle = 0 Then Notify "Unable to initialize the dll" End EndIf Global GetString()"Win32" = GetProcAddress(DllHandle,"GetString") Print GetString() The problem is that GetString() is returning a number (for ex. 84843344). I tried a lot of combination (adding a $, $z, etc) to try to get a string from my function, but I always failed... How can I do that??? |
| ||
Try Global GetString:Byte Ptr()"Win32" =GetProcAddress(DllHandle,"GetString") Print String.FromCString(GetString()) |
| ||
Fantastic! This works!! The only drawback is that the GetString() function is not any more user-friendly ("Print String.FromCString(GetString())" instead of "GetString()"). I have to redefine a function GetString2() which return String.FromCString(GetString()). That's a bit a pity!! Anyway, thank you very much for this!!!! |
| ||
Hi Test this Global GetString$z()"Win32" =GetProcAddress(DllHandle,"GetString") Print GetString() Mfg Suco |
| ||
Thanks! That's exactly what I was looking for! Suco-X, your solution is working perfectly!! And no need to redefine the GetString() function!! Many thanks! |
| ||
If the dll is written in BlitzMax, what would the function in the dll source look like?:Function GetString$() GCEnter() Return "This is a string!" EndFunction -- EDIT --- Answered my own question: Function PluginExtension:Byte Ptr() GCEnter() Local extension$ Local HExtension:Byte Ptr extension="smf" HExtension=extension.ToCString() Return HExtension EndFunction |