So this wee code snippet example uses the strings dll library (Ian M's matrix1 utils plugin) and gets an input string i.e. "test" and converts it to upper case using the plugin function "FastUpper". You can use Dependency Walker program to get the function names (undecorated). Have a play around with the code and try other functions. The main thing is for string returns , memory needs to be allocated (for some scenarios) and has to return a DWORD pointer to the string. I used Resource Hacker to look up the resource strings table for each command.
sync on : sync rate 30: sync
print "Loading Matrix1Util_16 dll..."
load dll "Matrix1Util_16.dll",1
if dll exist(1)=1
print "Calling DLL Function (FastUpper)...";
if dll call exist(1, "FastUpper")=1
print "okay."
//ptr as dword
//ptr = alloc(256)
ret as dword
ret = call dll (1,"FastUpper",0,"test")
print ret
t$=peek string(ret)
print t$
else
print "does not exist."
endif
print "Deleting DLL..."
delete dll 1
else
print "not loaded."
endif
sync
wait key
end
[recently added]
As in a previous post, here is how to return a string that uses the weird CreateDeleteString function used in the DBPRO globstruct.h.
Here, I've just added a dummy function with the ReverseString function. Which kind of defeats the object, but works as a quick workaround without having to do the whole pointer to globstruct stuff.
[recently added: meant to add that you can use any command from the dll to use in the dummy function and the dll needs to reside in the compiler plugin folder e,g, the user folder]
sync on : sync rate 30: sync
print "TestCommands2 dll..."
load dll "TestCommands2.dll",1
if dll exist(1)=1
print "Calling DLL Function (ReverseString)...";
if dll call exist(1, "?ReverseString@@YAKKK@Z")=1
print "okay."
ptr as dword
ptr = alloc(256)
fill memory ptr,0,256
poke string ptr,"Test"
ret as dword
ret = call dll (1,"?ReverseString@@YAKKK@Z",0,ptr)
print ret
t$=peek string(ret)
print t$
else
print "does not exist."
endif
print "Deleting DLL..."
delete dll 1
else
print "not loaded."
endif
sync
wait key
end
function Dummy$()
dum$=ReverseString$("dummy")
endfunction
Here's the whole of Matruxutils 14 functions being called (dummy function not required here):
sync on : sync rate 30: sync
print "Loading Matrix1Util_14 dll..."
load dll "Matrix1Util_14.dll",1
if dll exist(1)=1
print "Calling DLL Function (ProcessorCount)...";
if dll call exist(1, "ProcessorCount")=1
print "okay."
ptr as dword
ptr = call dll (1,"ProcessorCount")
print ptr
print "====================================="
else
print "does not exist."
endif
print "Calling DLL Function (ScancodeName)...";
if dll call exist(1, "ScancodeName")=1
print "okay."
ptr as dword
ptr = call dll (1,"ScancodeName",0,208)
print ptr
sc$=peek string(ptr)
print sc$
print "====================================="
else
print "does not exist."
endif
print "Calling DLL Function (UserName)...";
if dll call exist(1, "UserName")=1
print "okay."
ptr as dword
ptr = call dll (1,"UserName",0)
print ptr
user$=peek string(ptr)
print user$
print "====================================="
else
print "does not exist."
endif
print "Calling DLL Function (WindowsIs64Bit)...";
if dll call exist(1, "WindowsIs64Bit")=1
print "okay."
ptr as dword
ptr = call dll (1,"WindowsIs64Bit")
print ptr
print "====================================="
else
print "does not exist."
endif
print "Calling DLL Function (WindowsPlatform)...";
if dll call exist(1, "WindowsPlatform")=1
print "okay."
ptr as dword
ptr = call dll (1,"WindowsPlatform")
print ptr
print "====================================="
else
print "does not exist."
endif
print "Calling DLL Function (WindowsVersion)...";
if dll call exist(1, "WindowsVersion")=1
print "okay."
ptr as dword
ptr = call dll (1,"WindowsVersion")
print ptr
print "====================================="
else
print "does not exist."
endif
print "Deleting DLL..."
delete dll 1
else
print "not loaded."
endif
sync
wait key
end
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others