使用rundll32.exe运行dll函数

我们知道windows下dll是没办法独立运行的,但是微软提供了rundll32.exe用于运行dll。

先测试一下:运行“Rundll32.exe shell32.dll,RestartDialog”,会弹出重启对话框。同样这种方式可以打开windows系统其他功能。

下面看一下如何定义自己的dll让rundll32.exe运行。

微软给出的dll函数原型如下:

  void CALLBACK
  EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);

   hwnd - window handle that should be used as the owner window for
          any windows your DLL creates
   hinst - your DLL's instance handle
   lpszCmdLine - ASCIIZ command line your DLL should parse
   nCmdShow - describes how your DLL's windows should be displayed

自定义的测试dll如下:

extern "C" _declspec(dllexport) void __cdecl rundll32dllfun(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, 

int nCmdShow)
{
MessageBox(NULL,"TEST",lpszCmdLine,MB_OK);
return;
}

生成动态库rundll32dll.dll。

运行:

rundll32.exe "E:\demo\rudll32dll\Release\rudll32dll.dll",rundll32dllfun      

弹出了熟悉的对话框,说明调用成功。

同时可以传入参数,运行:

rundll32.exe "E:\demo\rudll32dll\Release\rudll32dll.dll",rundll32dllfun  888   

弹出了对话框,并且888显示了对话框上面,说明参数也可以传递了,其中参数在lpszCmdLine中获取。

运行命令说明:rundll32.exe "xxx.dll",dllfun parameter

这样我们就可以开发dll作为应用程序来运行了,在进程中只能看到rundll32.exe,需通过进程查看工具查看运行了哪个dll。


rundll32.exe在那里4位系统中的位置说明:

windows/system32/rundll32.exe对应调用64位dll

windows/SysWoW64/rundll32.exe对应调用32位dll

微软给出的参考文章如下:https://support.microsoft.com/zh-cn/kb/164787

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值