Use Rundll32.exe to execute the function exported by the DLL

I have a DLL that exports a function:

__declspec(dllexport) void __stdcall MyEntryPoint(char* params) { MessageBoxA("MyEntryPoint",params,0,0); } 

How can I use rundll32.exe to load my DLL and call MyEntryPoint() ?

+4
source share
1 answer

You need to define a function with a very specific signature so that it can be called by rundll32. See this blog post for information on how and why you might fail.

Also, take a look at this answer to a similar question, which details the function signature.

Essentially, for your function to be safe to call, you would need to define it something like:

 void CALLBACK MyEntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR pszCmdLine, int nCmdShow); 

or

 void CALLBACK MyEntryPointW(HWND hwnd, HINSTANCE hinst, LPWSTR pszCmdLine, int nCmdShow); 

Everything else will ruin the stack and may (or may not) cause a crash. I think that in later versions of Windows, rundll will first look for the MyEntryPointW function, and if a call is found, the difference is in the Unicode parameter pszCmdLine .

For more information on how to use rundll32 , see the MSDN , which details what to expect from each parameter, etc.

+8
source

Source: https://habr.com/ru/post/1394174/


All Articles