如何使用rundll32.exe从批处理中创建可调用的DLL [英] How to create a DLL callable from batch using rundll32.exe
问题描述
使用rundll32,可以将简单的API调用到DLL中.
With rundll32 it is possible to call simple APIs into DLLs.
两个问题:
- 为此用途,入口点应该使用
__ cdecl
调用约定还是其他调用约定? - 是否可以仅传递数字参数或字符串?
- for this usage, should be the entry point use the
__cdecl
calling convention, or some other calling convention? - is it possible to pass only numeric args or also strings?
推荐答案
请勿使用 rundll32.exe .我说不出比Raymond Chen更好的话:有关的指导是什么什么时候使用rundll32?容易:不使用它.
Don't use rundll32.exe. I can't word it any better than Raymond Chen did: What’s the guidance on when to use rundll32? Easy: Don’t use it.
如果您通读了博客条目,并且仍然确信这是您需要的解决方案,请参见交易:入口点必须遵循 __ stdcall
调用约定:
If you read through the blog entry, and are still convinced, that this is the solution you need, here is the deal: The entry point must follow the __stdcall
calling convention:
void CALLBACK
EntryPointW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow);
尾随的 W
很重要,因此 lpszCmdLine 参数作为Unicode(UTF-16LE)传递. EntryPoint 是一个占位符,可以是任何合法符号.
The trailing W
is important, so that the lpszCmdLine argument is passed as Unicode (UTF-16LE). EntryPoint is a placeholder, it can be any legal symbol.
作为示例,您可以导出名为 MyFunctionW
的符号,并使用以下命令传递任意命令行:
As an example, you can export a symbol called MyFunctionW
, and pass an arbitrary command line using:
rundll32.exe MyDll.dll,MyFunction 132 C:\WINDOWS\INF\SHELL.INF
但是,实际上,您应该评估其他选项(例如 PowerShell ).便利并非免费提供.
But really, you should evaluate other options (e.g. PowerShell). Convenience doesn't come for free.
这篇关于如何使用rundll32.exe从批处理中创建可调用的DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!