使用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

微软给出的参考文章如下:http://support2.microsoft.com/kb/164787

你可能感兴趣的:(使用rundll32.exe运行dll函数)