Search code examples
visual-studio-2010winapidllrundll32

Documentation for writting your own dll for Rundll32.exe?


Possible Duplicate:
How to use Rundll32 to execute DLL Function?

Where can I find documentation (tutorials, books, etc.) to write my own dll's that can be run with rundll32.exe?


Solution

  • Here is the most basic Hello World sample I could come up with that will work with rundll.exe. Please follow along these steps:

    Start a fresh WIN32 DLL project in Visual Studio (I used VS2010)

    In dlllmain.cpp add:

    // this shoud ideally go into the .h file I believe
    __declspec( dllexport ) void CALLBACK EntryPoint(
           HWND hwnd, 
          HINSTANCE hinst, 
          LPSTR lpszCmdLine, 
          int nCmdShow);
    
    // our hello world function
    void CALLBACK EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
    {
        int msgboxID = MessageBox(
            NULL,
            L"Hello World from Run32dll",
            L"Hello World",
            MB_ICONWARNING | MB_CANCELTRYCONTINUE | MB_DEFBUTTON2
        );
    
        switch (msgboxID)
        {
        case IDCANCEL:
            // TODO: add code
            break;
        case IDTRYAGAIN:
            // TODO: add code
            break;
        case IDCONTINUE:
            // TODO: add code
            break;
        }
    
    }
    

    Add a module.def file to your project and edit the following snippet in it:

    LIBRARY YourDll
    EXPORTS
        EntryPoint
    

    Compile and then test from the commandline with

    rundll32 YourDll.dll,EntryPoint
    

    You should be greeted with a MessageBox with three buttons

    I used the following url's to overcome C++ issues and EntryPoint not found in the early stages of my effort: