With rundll32 it is possible to call simple APIs into DLLs.
Two questions:
- 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?
With rundll32 it is possible to call simple APIs into DLLs.
Two questions:
__cdecl
calling convention, or some other calling convention?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.
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);
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.
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
But really, you should evaluate other options (e.g. PowerShell). Convenience doesn't come for free.
The entry point must use the __stdcall
calling convention:
void CALLBACK
EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);
This is covered in the following documentation: