Skip navigation

Creating Your Own DLL

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. The only 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 perform dynamic linking at runtime. Dynamic linking is the process that lets one piece of code, such as SMS Administrator, call on other code, such as our custom resource-only DLL, that is not in the calling program's executable. The entry point tells NT where to start running the DLL's code when it is called from another application.

Because you're creating a DLL that just stores resources for SMS to use (a resource-only DLL), you don't need to do a lot of C++ programming. You only need to use some standard hook-up code that all DLLs contain. Listing A shows sample code, resdll.c, that comes with the SMS software development kit (SDK) for developing 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.h file referenced by the include statement into my file­this coding saves retyping this information in resdll.c. The DllMain function begins with the line that starts with BOOL APIENTRY. Note the Nothing to initialize comment. DllMain's primary purpose is to let you do any necessary initialization of data structures and memory allocations before an application such as SMS starts to use the DLL. Because you don't need to initialize anything, the program simply returns TRUE, signaling that the DllMain function successfully completed.

As I mentioned in the main article, you don't need to obtain this C++ code if 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 treat the file as a C++ file­see, you just became a C++ programmer!).

The Resource Script
The resource script identifies and describes the graphic resources that you want to include in the DLL. Resource scripts can get pretty complicated, but the script for this task is simple. The minimum script for adding 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 when NT 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 to get a printer bitmap into your resource-only DLL.

LISTING A: The Sample resdll.c C++ File

#include <windows.h> 
// ************************************************************** 
// 
// 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; 
\} 
Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish