Not sure how useful this would be I just fancied the challenge of making it work
This plugin will enable you to call functions in dynamic link library's directly from Tier 1 code (windows only) without needing them formatted as a plugin, it currently only supports functions with up to 5 arguments but I can expand this to support upto 20 arguments, it also only supports string and integer argument types and integer returns, this is a limitation of PureBasic but I think I can code a work-a-round, I might be able to support string returns depends on the demand but for now I'm pretty happy it works as there's many library's out there that could be useful even with the limitations.
Edit: Now supports 20 max arguments and string returns via memory buffer
Added functions:
Library.Alloc()
Library.DeAlloc()
Library.Peek()
Example using GetClassNameA
if Library.Open(1,"User32.dll")
FindWindow = Library.GetFunction(1, "FindWindowA")
Library.PutIntParam(0)
Library.PutStringParam("Library")
HWND=Library.CallFunction(FindWindow)
Library.ClearParams()
Buffer=Library.Alloc(255)
GetClassName = Library.GetFunction(1, "GetClassNameA")
Library.PutIntParam(HWND)
Library.PutIntParam(Buffer)
Library.PutIntParam(255)
Library.CallFunction(GetClassName)
Library.ClearParams()
classname$=Library.Peek(Buffer)
Library.DeAlloc(Buffer)
Library.Close(1)
endif
do
print(classname$)
Sync()
loop
heres a few basic usage examples
// show a message box
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms645505(v=vs.85).aspx
if Library.Open(1,"User32.dll")
FindWindow = Library.GetFunction(1, "FindWindowA")
Library.PutIntParam(0)
Library.PutStringParam("Library")
HWND=Library.CallFunction(FindWindow)
Library.ClearParams()
MessageBox = Library.GetFunction(1, "MessageBoxA")
Library.PutIntParam(HWND)
Library.PutStringParam("Message")
Library.PutStringParam("Title")
Library.PutIntParam(306)
Library.CallFunction(MessageBox)
Library.ClearParams()
Library.Close(1)
endif
// play a beep sound
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms679277(v=vs.85).aspx
if Library.Open(1,"Kernel32.dll")
Beep = Library.GetFunction(1, "Beep")
Library.PutIntParam(750)
Library.PutIntParam(1000)
Library.CallFunction(Beep)
Library.ClearParams()
Library.PutIntParam(1750)
Library.PutIntParam(1000)
Library.CallFunction(Beep)
Library.ClearParams()
Library.Close(1)
endif
// play a message beep
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680356(v=vs.85).aspx
if Library.Open(1,"User32.dll")
MessageBeep = Library.GetFunction(1, "MessageBeep")
Library.PutIntParam(16)
Library.CallFunction(MessageBeep)
Library.ClearParams()
Library.Close(1)
endif
// show shell about dialog
// https://msdn.microsoft.com/en-us/library/windows/desktop/bb762152(v=vs.85).aspx
if Library.Open(1,"User32.dll")
if Library.Open(2,"Shell32.dll")
FindWindow = Library.GetFunction(1, "FindWindowA")
Library.PutIntParam(0)
Library.PutStringParam("Library")
HWND=Library.CallFunction(FindWindow)
Library.ClearParams()
ShellAbout = Library.GetFunction(2, "ShellAboutA")
Library.PutIntParam(HWND)
Library.PutStringParam("My App Name")
Library.PutStringParam("My App Info")
Library.PutIntParam(0)
Library.CallFunction(ShellAbout)
Library.ClearParams()
Library.Close(1)
Library.Close(2)
endif
endif
if anyone finds it useful let me know and I'll expand the function set, I don't own any DBPro dll's but I'm curious to know if this system will help support them, anyone want to colab?, are they even compatible?