Recently I pushed a bug fix to GitHub that would allow us to have Windows applications in Vista and higher be DPI aware. I accomplished this using
LoadLibrary, a function in the WinAPI that allows for linking a library at runtime rather than at compilation. You then use
GetProcAddress to find the address of the function that you are wanting to use from the DLL. You can call the function from that DLL at runtime by calling that address. This allowed me to not have to link the user32.dll library in the
_NEWIMAGE function but instead just call it at runtime by finding the DLL and the function. So, since that worked so well, I've made some code here that I think could inspire others who are interested in DLL usage in the Windows environment to try some new things:
//this code would be saved as runtimecall.h
long runtimeCall(LPCSTR dllName, LPCSTR processName){
FARPROC runtime;
HMODULE dllLoad = LoadLibrary(TEXT(dllName));
if(dllLoad != NULL){
runtime = GetProcAddress(dllLoad, processName);
if(NULL != runtime){
return (runtime) ();
FreeLibrary(dllLoad);
}
else{
return -807;
FreeLibrary(dllLoad);
}
}
else{
return -808;
}
}
And an example of the code's usage:
Print runtimeCall
("kernel32.dll", "GetLastError")
Obviously, if you want to pass parameters to the functions then you would need to change the function in the header and in the BAS code but this is just a concept showing a familiar WinAPI function being called using runtime linking rather than linking during compilation.