Click here to Skip to main content
14,972,640 members
Articles / Desktop Programming / WTL
Posted 24 Apr 2003


104 bookmarked

Screen Event Recorder DLL/Application

Rate me:
Please Sign up or sign in to vote.
4.91/5 (34 votes)
9 May 2003MIT3 min read
Screen Event Recorder (DLL) shows how to create a DLL/Application (one that can be used with RunDll32.exe).

Sample Image - EventRecorder.gif


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.


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.


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:

void CALLBACK EntryPoint(
    HWND hwnd,        // handle to owner window
    HINSTANCE hinst,  // instance handle for the DLL
    LPTSTR lpCmdLine, // string the DLL will parse
    int nCmdShow      // show state

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


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

    C:\Program Files\EventRecorder\MacRcrd.dll,PlayFile

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.



@="Event File"



[HKEY_CLASSES_ROOT\EventFile\shell\Start Player]

[HKEY_CLASSES_ROOT\EventFile\shell\Start Player\command]
@="RunDll32.exe C:\\Progra~1\\EventRecorder\\MacRcrd.dll,PlayFile /file:%1"

[HKEY_CLASSES_ROOT\EventFile\shell\Play Events]

[HKEY_CLASSES_ROOT\EventFile\shell\Play Events\command]
    C:\\Progra~1\\EventRecorder\\MacRcrd.dll,PlayFile /play /file:%1"

Statically or dynamically linked to other application

Using this DLL as statically linked to your application is also possible. This is made easy on you by just including

#include "MacRcrdImport.h"

in your project. This Event recorder DLL (MacRcrd.dll) exposes the following interfaces:

HRESULT InstallCBT( LONG_PTR lEventObj, 
    LONG_PTR lEventObjInstance, DWORD fdwOptions );
HRESULT UninstallCBT();
HRESULT InstallRecorder( LONG_PTR lEventObj, 
    LONG_PTR lEventObjInstance, DWORD fdwOptions );
HRESULT UninstallRecorder();
HRESULT InstallPlayer( LONG_PTR lEventObj, 
    LONG_PTR lEventObjInstance, DWORD fdwOptions );
HRESULT UninstallPlayer();

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:

    WPARAM wParam, LPARAM lParam, LONG_PTR dwInstance);

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.


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


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


About the Author

Ernest Laurentin
Software Developer (Senior)
United States United States
Ernest is a multi-discipline software engineer.
Skilled at software design and development for all Windows platforms.
Interests: User Interface, GDI/GDI+, Scripting, Android, iOS, Windows Mobile.
Programming Skills: C/C++, C#, Java (Android), VB and ASP.NET.

I hope you will enjoy my contributions.

Comments and Discussions

Questionany new version of event recorder available for windows 8 or 8.1 Pin
Member 112184749-Nov-14 0:08
MemberMember 112184749-Nov-14 0:08 
GeneralMy vote of 5 Pin
maq221-Sep-13 3:53
Membermaq221-Sep-13 3:53 
QuestionHow to use Screen Event Recorder DLL in VB or VBA Pin
steventoh13-Oct-10 2:11
Membersteventoh13-Oct-10 2:11 
GeneralImpressive Pin
Dr.Luiji11-Dec-08 20:56
professionalDr.Luiji11-Dec-08 20:56 
GeneralVista Pin
B4stard9-Aug-07 16:29
MemberB4stard9-Aug-07 16:29 
QuestionTime Moves On Pin
Finbar18-Feb-07 10:59
MemberFinbar18-Feb-07 10:59 
AnswerRe: Time Moves On Pin
Ernest Laurentin18-Feb-07 11:15
MemberErnest Laurentin18-Feb-07 11:15 
QuestionRe: Time Moves On Pin
Finbar18-Feb-07 11:48
MemberFinbar18-Feb-07 11:48 
AnswerRe: Time Moves On Pin
ftas25-Jun-07 4:48
Memberftas25-Jun-07 4:48 
GeneralExcellent, but have you a release based also on windows event Pin
snoopy246623-Aug-06 23:55
Membersnoopy246623-Aug-06 23:55 
Generalbuilding media player Pin
sumitgupta2219-Jan-06 0:51
Membersumitgupta2219-Jan-06 0:51 
GeneralRe: building media player Pin
Ernest Laurentin19-Jan-06 14:20
MemberErnest Laurentin19-Jan-06 14:20 
GeneralSome issues Pin
RussianDevil18-Jul-05 16:05
MemberRussianDevil18-Jul-05 16:05 
GeneralHelp no actions with keyboard and mouse Pin
OkDoc17-Nov-04 9:24
MemberOkDoc17-Nov-04 9:24 
QuestionMacRcrd.vcproj missing? Pin
Member 3280216-Jun-04 23:35
MemberMember 3280216-Jun-04 23:35 
AnswerRe: MacRcrd.vcproj missing? Pin
Member 3280217-Jun-04 1:31
MemberMember 3280217-Jun-04 1:31 
GeneralAutomatic test framework for gui Pin
winecad6-Apr-04 12:59
Memberwinecad6-Apr-04 12:59 
Generalcreating mfc event dll Pin
Xins10-Mar-04 16:54
MemberXins10-Mar-04 16:54 
QuestionHow can I Debug using RunDll32.exe Pin
Aisha Ikram17-Nov-03 18:28
MemberAisha Ikram17-Nov-03 18:28 
AnswerRe: How can I Debug using RunDll32.exe Pin
Ernest Laurentin20-Nov-03 17:44
MemberErnest Laurentin20-Nov-03 17:44 
GeneralSimply genial Pin
leirbagz5-Oct-03 0:10
Memberleirbagz5-Oct-03 0:10 
GeneralRe: Simply genial Pin
Ernest Laurentin5-Oct-03 18:39
MemberErnest Laurentin5-Oct-03 18:39 
GeneralDon't run! Pin
nikouhl20-Sep-03 12:05
Membernikouhl20-Sep-03 12:05 
GeneralRe: Don't run! Pin
Aisha Ikram13-Nov-03 20:17
MemberAisha Ikram13-Nov-03 20:17 
GeneralRe: Don't run! Pin
Ernest Laurentin14-Nov-03 19:55
MemberErnest Laurentin14-Nov-03 19:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.