Creating Your Own DLL
Here is how to create your own DLL with custom graphic resources.
February 28, 1997
To create your own DLL with custom graphic resources for SMS to use,you need to provide two code files to develop the DLL. The first file is the C++code, smscust.cpp, and the other file is a resource script file, smscust.rc. Theonly other files you need are the bitmap and icon files that you create.
The C++ Code
The smscust.cpp file contains the DLL entry point that NT uses to performdynamic linking at runtime. Dynamic linking is the process that lets one pieceof code, such as SMS Administrator, call on other code, such as our customresource-only DLL, that is not in the calling program's executable. The entrypoint tells NT where to start running the DLL's code when it is called fromanother application.
Because you're creating a DLL that just stores resources for SMS to use (aresource-only DLL), you don't need to do a lot of C++ programming. You only needto use some standard hook-up code that all DLLs contain. Listing A shows samplecode, resdll.c, that comes with the SMS software development kit (SDK) fordeveloping a resource-only DLL. The only function in the DLL is DllMain,the so-called entry point for all DLLs (everything following a // is a comment).The #include tells the compiler to copy all the code from the windows.hfile referenced by the include statement into my filethiscoding saves retyping this information in resdll.c. The DllMain function beginswith the line that starts with BOOL APIENTRY. Note the Nothing to initializecomment. DllMain's primary purpose is to let you do any necessaryinitialization of data structures and memory allocations before an applicationsuch as SMS starts to use the DLL. Because you don't need to initializeanything, the program simply returns TRUE, signaling that the DllMainfunction successfully completed.
As I mentioned in the main article, you don't need to obtain this C++ codeif you have Visual C++ (VC++); it can generate this code for you automatically.However, if you don't have VC++, copy resdll.c from the SMS SDK and rename it smscust.cpp for your custom DLL (the .cpp extension tells the compiler to treatthe file as a C++ filesee, you just became a C++ programmer!).
The Resource Script
The resource script identifies and describes the graphic resourcesthat you want to include in the DLL. Resource scripts can get prettycomplicated, but the script for this task is simple. The minimum script foradding a printer bitmap, printer.bmp, whose resource name is PRINTER_
PRINTER is as follows:
PRINTER_PRINTER BITMAP DISCARDABLE "Printer.bmp"
The resource script identifies the resource as a BITMAP that is DISCARDABLE.The DISCARDABLE keyword tells NT that it can remove the bitmap from memory whenNT needs to access memory because NT can safely reload the image if needed.Although you can add some other entries to smscust.rc, this code is enough toget a printer bitmap into your resource-only DLL.
LISTING A: The Sample resdll.cC++ File
#include // ************************************************************** // // Function: DllMain(HANDLE, DWORD, LPVOID) // // ************************************************************** // // Description: // // This is the main initialization routine called by the NT // kernel when a new thread requests use of the DLL. It's also // called when a thread stops using the DLL. A parameter passed // to the function identifies the reason for calling. // // ************************************************************** BOOL APIENTRY DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved) { // Nothing to initialize. return TRUE; }
About the Author
You May Also Like