Running a full windows app in a dll via rundll32

768 Views Asked by At

Does anyone have an example of building a complete WIN32 Windows app as a dll?

I'd like to export a function, call it via rundll32, and have a complete Windows app with decorations, a menu, accelerators, and everything pop up.

I know about the calling convention for rundll32:

void CALLBACK TestEntryW(HWND hWnd, HINSTANCE hInst, LPWSTR pszCmdLine, int nCmdShow);

I can pull up a MessageBox from that function via the command: rundll32.exe test3.dll,TestEntry other params and args

I can load resources from my DLL by getting the DLL's handle via GetModuleHandle("test3.dll") and using that as hInst in my LoadString calls. That seems to be working for LoadIcon and LoadAccelerators as well, but I don't have working yet (baby steps..).

I can register a Windows class via RegisterClassEx using those strings and icons, but I must use the parent hInst or I get ERROR_CANNOT_FIND_WND_CLASS when calling CreateWindow. I think that's expected.

However, When I try to use that class in CreateWindow, it returns NULL, and so does GetLastError.

I can retrieve the window class of the hInst passed from rundll32 using GetWindowsLong(hWnd, GWL_ATOM). Using that for lpClassName, I can pull up a decorated window minus menus and accelerators, but it's a bit funky, as rundll's window class is normally only used for its message queue. I tried subclassing the window using SetWindowsLong to replace the WndProc and calling CallWindowProc instead of DefWindowProc in my dll's WndProc.

I'm hampered by being unable to debug it in MSVC++ 2010 Express. I replaced the project's command and command arguments with the appropriate entries so it launches it correctly, but it complains about no debugging info for rundll32.exe, and breakpoints etc. don't work.

Any ideas? Am I on the right track?

0

There are 0 best solutions below