为 Rundll32.exe 编写自己的 dll 的文档? [英] Documentation for writting your own dll for Rundll32.exe?

查看:17
本文介绍了为 Rundll32.exe 编写自己的 dll 的文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
如何使用Rundll32执行DLL函数?

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

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

推荐答案

这是我能想到的最基本的 Hello World 示例,它可以与 rundll.exe 一起使用.请按照以下步骤操作:

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

在 Visual Studio 中新建一个 WIN32 DLL 项目(我用的是 VS2010)

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

在 dllmain.cpp 中添加:

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

}

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

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

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

You should be greeted with a MessageBox with three buttons

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

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

这篇关于为 Rundll32.exe 编写自己的 dll 的文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆