Hi,
I've some problems when linking to some WinAPI functions, the linker tells me that there's an undefined reference, however I'm sure this function exists:
Now I'm wondering what Extern "Win32" actually does.
Till now I thought it puts a notice into the compiled executable which indicates that the executable's code needs these functions. When the operating system executes this application, it checks whether these functions are available and if they are, it loads the modules of the required libraries and links them to the code in the executable, only if this was successfully it really executes the code. If there were problems with loading the libraries or if the functions aren't available it produces a system error message.
Since the code above doesn't work, I'm currently believing BlitzMax links the extern declarations to a static library which does the run-time linking. And this library isn't up-to-date and therefore doesn't support the functions I listed. This could be an explanation for why the functions I listed above can't be linked to. However, if this is true, I don't like this behaviour; it would be much better if BlitzMax would directly link to the dynamic libraries, not using any static c-like library doing this job.
The solution I found is just doing like I did in the second code box: load the library manually while the application is running and then query the function's address. It works, however, if the functions are not available I'm forced to display an error message myself, this would be an application defined notify box or something like this, but it isn't the system standard. I'd prefer that the process wouldn't start at all if the function's aren't available and the operating system checks whether the functions are available and produces a system standard error message if not.
I've some problems when linking to some WinAPI functions, the linker tells me that there's an undefined reference, however I'm sure this function exists:
Strict Framework brl.blitz Global Variable Local ModHandle If GetModuleHandleExW ( 6 , Varptr Variable , Varptr ModHandle ) WriteStdout "The memory used for this variable is located in the following module: " + ModHandle + "~n" EndIf Extern "Win32" Function GetModuleHandleExW ( Flags , Name:Byte Ptr , ModHandle Ptr ) EndExternThis gives me an error when linking, however, this works:
Strict Framework brl.blitz Global Variable Local Kernel32 = LoadLibraryW ( "Kernel32.dll" ) Local GetModuleHandleExW ( Flags , Name:Byte Ptr , ModHandle Ptr ) "Win32" = GetProcAddress ( Kernel32 , "GetModuleHandleExW" ) Local ModHandle If GetModuleHandleExW ( 6 , Varptr Variable , Varptr ModHandle ) WriteStdout "The memory used for this variable is located in the following module: " + ModHandle + "~n" EndIf FreeLibrary Kernel32 Extern "Win32" Function LoadLibraryW ( Name$w ) Function GetProcAddress:Byte Ptr ( Library , Name$z ) Function FreeLibrary ( Library ) EndExternI've also noticed some other functions which can't be linked: GetProcessMemoryInfo, EnumProcesses, EnumProcessModules, GetModuleBaseName, GetProcessImageFileName, AuthzFreeHandle, GetProcessId, DebugActiveProcessStop, CredFree, GetNativeSystemInfo
Now I'm wondering what Extern "Win32" actually does.
Till now I thought it puts a notice into the compiled executable which indicates that the executable's code needs these functions. When the operating system executes this application, it checks whether these functions are available and if they are, it loads the modules of the required libraries and links them to the code in the executable, only if this was successfully it really executes the code. If there were problems with loading the libraries or if the functions aren't available it produces a system error message.
Since the code above doesn't work, I'm currently believing BlitzMax links the extern declarations to a static library which does the run-time linking. And this library isn't up-to-date and therefore doesn't support the functions I listed. This could be an explanation for why the functions I listed above can't be linked to. However, if this is true, I don't like this behaviour; it would be much better if BlitzMax would directly link to the dynamic libraries, not using any static c-like library doing this job.
The solution I found is just doing like I did in the second code box: load the library manually while the application is running and then query the function's address. It works, however, if the functions are not available I'm forced to display an error message myself, this would be an application defined notify box or something like this, but it isn't the system standard. I'd prefer that the process wouldn't start at all if the function's aren't available and the operating system checks whether the functions are available and produces a system standard error message if not.