Introduction

This article presents a powerful DLL. I say powerful since it offers some advantages over standard library DLL. This DLL not only can be linked to your application; it can also be run as a stand-alone application.

Description

Almost every time a developer will develop a library, a separate application will be created to use it. But at times, the logic in the GUI is so simple, there is no need for it. By using the RunDll.exe utility provided with Windows (generally under System32 folder), a developer can automatically provide the required GUI inside of the DLL itself. This eliminates the need to write a separate application to use it. Such DLLs doesn't need to be programmed only with Win32 API, you can also use MFC/ATL/WTL library if you wish to do so.

RunDLL

MSDN: The Run DLL utility (Rundll32.exe) included in Windows enables you to call functions exported from a 32-bit DLL. These functions must have the following syntax:

Windows NT/2000/XP: It is possible to create a Unicode version of the function. Rundll32 first tries to find a function named EntryPointW. If it cannot find this function, it tries EntryPointA, then EntryPoint. To create a DLL that supports ANSI on Windows 95/98/ME and Unicode otherwise, export two functions: EntryPointW and EntryPoint.

When our main function PlayFile is called, HWND hwnd points to the RunDLL window class. This window is normally hidden and the main thread inside of the RunDll.exe application is running its message loop. Thus, to terminate the running thread, you only need to call PostQuitMessage(). The DLL/Application is able to record/play user input events. It can be viewed as a full feature application capable to record mouse and keyboard activities. A file can be created (.evr) and played at later time. This can be useful to automate testing for your application.

How to Use

Stand-Alone

To use this DLL as stand-alone, you can create a shortcut with the following:

You can also use the exported registry settings file (.reg) which can used to register the event recorder file extension to your computer so that you can use explorer to execute a recorder file by using the context menu command.

The function InstallRecorder installs a journal record hook while the InstallPlayer installs a journal playback hook in the system. You can provide a CALLBACK function as the event object a window handle. I do not recommend to use the window handle for now, since the callback method provide much more functionalities. The callback must follow this prototype:

I recommend you to take a look inside PlayFile.cpp for an example of how this can be used. Remember that WM_CANCELJOURNAL is posted to your MFC application but with RunDll32.exe, this message cannot be seen very easily. In order to see this message inside of your DLL, you will need to run your own message loop by using GetMessage or PeekMessage or you can also install a GetMsgProc hook procedure function.

Conclusion

I introduced in this article a DLL/Application, which is not very different to control panel application (same principle), but offer some advantages to regular DLL. In software design, DLL/Application can be very useful and may offer a very attractive solution to your design. This project demonstrates various techniques like:

Using Journal recorder and playback (WH_JOURNALRECORD and WH_JOURNALPLAYBACK)

Using ComCtl32 Version 6 in Control Panel or a DLL That is run by RunDll32.exe

Exporting and renaming exported functions from source code

Parsing command-line argument

Revision History

v1.5.0.0 - Bug fixes, Added CPlayFileDlg ATL-class

v1.0.0.0 - Initial release

License

This article, along with any associated source code and files, is licensed under The MIT License

I wish to use this MacRcrd.dll in my VBA but google around, cannot find any example.
I need it to record control keystroke(example Tab, Enter, Ctrl ) and play it on application that refuse to accept keybd_event and sendkeys method.
Hope someone can offer an example in VB as I do not understand C programming

How do I rewrite this to work under Vista, given that journal hooks no longer work? I only want to be able to capture and play back user input within my own application.
I've read that the hooks will work if the application is signed + has a manifest + is installed under program files, but that isn't going to happen.
Can it be done using WH_KEYBOARD and WH_MOUSE hooks?

Have tried using the DLL from this project. First thing I noticed is when I record clicking on the shortcut in the QuickLaunch taskbar (bottom panel on my desktop of my XP box), during replay the invoked application window doesn't seem to be shown... so the mouse movements which operate on it end up operating on whatever the active window is at the time of the replay.

During one of the replays the speed of events seemed to be super-quick compared to the speed at which I moved the mouse during the recording.

Finally, after a couple of runs the DLL started to cause my workstation to become hanging as soon as I pressed the 'Record' button. I had to press 'Ctrl-Alt-Delete' to remove the journal hook and terminate the application.

Is there any way i can debug your dll code using RunDll32.exe? If yes, can you please specify it. I set "C:\WINDOWS\system32\rundll32.exe" as an executable for debug session and it's not working, i think i need to specify "PlayFile" entry function as well ... but i am not sure about the format . Did u tried this??

Yes to debug it:
Executable for debug:
{drive:}\windows\system32\RunDll32.exe
Arguments:
{$OutDir}\MacRcrd.dll,PlayFile
I usually set the working directory to:
{$OutDir}
Of course, $OutDir is the output directory
Thanks for voting...

I have the new SDK 2003 from Microsoft and the WTL70. I compile your project and i start the dll with the rundll32. But nothing happens.... No error message ... nothing!!! I use WinXP... What's wrong?????