摘录自"programming windows(charles petzold)"
1
a dynamic library module doesn't receive messages. However, a library module can call GetMessage and PeekMessage . The messages the library pulls from the queue with these functions are actually messages for the program that called the library function. In general, the library works on behalf of the program calling it. 也就是说你不能给一个DLL发送消息, 你只能给一个EXE发送消息. 但是DLL 可以调用getmessage 或者 peekmessage去读取EXE中的消息.
2
A dynamic library can load resources (such as icons, strings, and bitmaps) either from the library file or from the file of the program that calls the library. The functions that load resources require an instance handle. If the library uses its own instance handle (which is passed to the library during initialization), the library can obtain resources from its own file. To load resources from the calling program's .EXE file, the library function requires the instance handle of the program calling the function.
3
Registering window classes and creating windows in a library can be a little tricky. Both the window class structure and the CreateWindow call require an instance handle. Although you can use the library module's instance handle in creating the window class and the window, the window messages still go through the message queue of the program calling the library when the library creates the window. If you must create window classes and windows within a library, it's probably best to use the calling program's instance handle.
在DLL中你也可以进行创建窗口等方面的工作, 问题是即使你在DLL中用DLL的instance创建了该窗口,那DLL也不会得到那些发给该窗口的消息,必须要调用getMessage或PeekMessage去EXE的queue中读取消息.
4
Because messages for modal dialog boxes are retrieved outside a program's message loop, you can create a modal dialog box in a library by calling DialogBox . The instance handle can be that of the library, and the hwndParent argument to DialogBox can be set to NULL.
5
动态使用dll:
typedef BOOL (WINAPI * PFNRECT) (HDC, int, int, int, int) ;
HANDLE hLibrary ;
PFNRECT pfnRectangle ;
Miscellaneous DLL Topics
hLibrary = LoadLibrary (TEXT ("GDI32.DLL"))
pfnRectangle = (PFNPRECT) GetProcAddress (hLibrary, TEXT ("Rectangle"))
pfnRectangle (hdc, xLeft, yTop, xRight, yBottom) ;
FreeLibrary (hLibrary) ;
Miscellaneous DLL Topics
Although this technique of run-time dynamic linking doesn't make much sense
for the Rectangle
function, it can come in handy when you don't know the
name of the library module until run time.
The code above uses the LoadLibrary
and FreeLibrary
functions.
Windows maintains "reference counts" for all library modules. LoadLibrary
causes the reference count to be incremented. The reference count is also
incremented when Windows loads any program that uses the library.
FreeLibrary
causes the reference count to be decremented, as does the
termination of an instance of a program that uses this library. When the
reference count is 0, Windows can discard the library from memory, because the
library is no longer needed.
6
理解.rc .h??
7
Any function in a dynamic-link library that a Windows program or another library
can use must be exported. However, a DLL need not contain any exported
functions. What would such a DLL contain? The answer is resources.
8
Let's say you're working on a Windows application that requires a number of
bitmaps. Normally you would list these in the resource script of the program and
load them into memory with the LoadBitmap
function. But perhaps you want
to create several sets of bitmaps, each set customized for one of the major
display resolutions commonly used with Windows. It would make most sense to
store these different sets of bitmaps in different files, because a user would
need only one set of bitmaps on the fixed disk. These files are resource-only
libraries.
正常情况下,我们如果需要一些bitmaps的话, 就会放在EXE中, 利用loadbitmap去使用它们.
但是当你有许多套的bitmaps的时候, 不同用户只需要其中的一套的话,那放在DLL中就有意义了.
而且这样的话也会减少EXE的空间.
关于如何制作这样的DLL, 可以参考programming windows(charles petzold)
figure21-5
7万+

被折叠的 条评论
为什么被折叠?



