为Rundll32.exe编写自己的dll的文档?

时间:2012-08-06 07:24:08

标签: visual-studio-2010 winapi dll rundll32

  

可能重复:
  How to use Rundll32 to execute DLL Function?

在哪里可以找到文档(教程,书籍等)来编写我自己的可以用rundll32.exe运行的dll?

1 个答案:

答案 0 :(得分:4)

以下是我能提出的最基本的Hello World示例,它将与rundll.exe一起使用。请按照以下步骤操作:

在Visual Studio中启动一个全新的WIN32 DLL项目(我使用的是VS2010)

在dlllmain.cpp中添加:

// 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;
    }

}

在项目中添加module.def文件并编辑其中的以下代码段:

LIBRARY YourDll
EXPORTS
    EntryPoint

编译然后使用

从命令行进行测试
rundll32 YourDll.dll,EntryPoint

你应该看到一个带有三个按钮的MessageBox

在我努力的早期阶段,我使用以下网址来克服C ++问题和 EntryPoint not found