SYS"LoadLibrary"

Discussions related to graphics (2D and 3D), animation and games programming
KenDown
Posts: 327
Joined: Wed 04 Apr 2018, 06:36

SYS"LoadLibrary"

Post by KenDown »

In my Display program I already INSTAL@LIB$+"GDIPLIB" and in the initialisation routine it instructs the computer to
SYS"LoadLibrary","GDIPLUS.DLL" TO gdip%

and then proceeds to set up a whole lot of variables in the form
SYS "GetProcAddress", gdip%, "GdiplusStartup" TO `GdiplusStartup`

Now I want to use IMGLIB and one of the first instructions in the initialisation routine is
SYS"LoadLibrary","GDIPLUS.DLL"TO L@imglib%

Do I end up with two copies of GDIPLUS.DLL with consequent possible confusion as they both define `GdiplusStartup` or is the SYS"LoadLibrary" call smart enough to recognise that GDIPLUS.DLL is already loaded? Does anyone know or have any method of finding out?
KenDown
Posts: 327
Joined: Wed 04 Apr 2018, 06:36

Re: SYS"LoadLibrary"

Post by KenDown »

This web page, although referring to "LoadLibraryA" appears to answer my question.

https://docs.microsoft.com/en-us/window ... adlibrarya

"If the specified module is a DLL that is not already loaded for the calling process, the system calls the DLL's DllMain function with the DLL_PROCESS_ATTACH value. If DllMain returns TRUE, LoadLibrary returns a handle to the module. If DllMain returns FALSE, the system unloads the DLL from the process address space and LoadLibrary returns NULL. It is not safe to call LoadLibrary from DllMain. For more information, see the Remarks section in DllMain.

"Module handles are not global or inheritable. A call to LoadLibrary by one process does not produce a handle that another process can use — for example, in calling GetProcAddress. The other process must make its own call to LoadLibrary for the module before calling GetProcAddress.

"If lpFileName does not include a path and there is more than one loaded module with the same base name and extension, the function returns a handle to the module that was loaded first."

I can't make much sense of the first paragraph quoted above but reference to "already loaded" appears to imply that the routine does *not* re-load the file. On the other hand the third paragraph seems to imply that the module *is* loaded twice (or more) but subsequent loads are just ignored - but does that mean that memory and program space are taken up by the second loading?

Hmmmm.