Calling LoadLibrary() on a 16-bit DLL

ID: Q123731

1.30 1.30a 1.30c WINDOWS kbprg kbhowto

The information in this article applies to:

SUMMARY

In Win32-based applications, LoadLibrary() returns an HINSTANCE and GetLastError() is used to determine the error. If HINSTANCE is NULL, the DLL was not successfully loaded. If the HINSTANCE is not null, the DLL was loaded and the usage count was incremented; however, you may still see that the last error was set if the DLL is a 16-bit DLL.

NOTE: At this point, the DLL is loaded and the usage count is incremented. Call FreeLibrary() to unload the DLL.

MORE INFORMATION

In order to see all possible error returns, you'll need to call SetLastError(0) before calling LoadLibrary(). If HINSTANCE is not NULL and GetLastError() is ERROR_BAD_EXE_FORMAT, the DLL is a 16-bit DLL. You can access the DLL resources and/or printer APIs from your Win32-based application.

To call routines in the 16-bit DLL, you should load and call the DLL via the Universal Thunk. This increments the usage count again. Later, you can use FreeLibrary() to free the DLL from the 16-bit code, but this won't unload the DLL from memory unless you already called FreeLibrary() from the 32-bit code. This is because the usage count is not zero. We recommend you call FreeLibrary() from the 32-bit code after the DLL is loaded by the 16-bit code, so the DLL isn't unloaded and then reloaded.

REFERENCES

For more information on how to get resources from a 16-bit DLL, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q105761
   TITLE     : Getting Resources from 16-bit DLLs Under Win32s

For more information on Universal Thunk, please see Chapter 4 of the Win32s Programmer's Reference.

KBCategory: kbprg kbhowto KBSubcategory: W32s Additional reference words: 1.30 1.30a 1.30c

Keywords          : kbWin32s 
Version           : 1.30 1.30a 1.30c
Platform          : WINDOWS

Last Reviewed: January 5, 1997