Click here to Skip to main content
Click here to Skip to main content
Go to top

Screen Event Recorder DLL/Application

, 9 May 2003
Rate this:
Please Sign up or sign in to vote.
Screen Event Recorder (DLL) shows how to create a DLL/Application (one that can be used with RunDll32.exe).

Sample Image - EventRecorder.gif

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:

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

Stand-Alone

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

%windir%\System32\RunDll32.exe 
    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.

REGEDIT4

[HKEY_CLASSES_ROOT\.evr]
@="EventFile"

[HKEY_CLASSES_ROOT\EventFile]
@="Event File"

[HKEY_CLASSES_ROOT\EventFile\DefaultIcon]
@="C:\\Progra~1\\EventRecorder\\MacRcrd.dll"

[HKEY_CLASSES_ROOT\EventFile\shell]
@=""

[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]
@="RunDll32.exe 
    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:

typedef LRESULT (CALLBACK* PFNCALLBACK)(int nCode, 
    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.

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

Share

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.
-
MCSD (C#, .NET)
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

 
Suggestionhttp://automatemytasks.weebly.com PinmemberMember 1093440018-Jul-14 2:52 
GeneralMy vote of 5 Pinmembermaq221-Sep-13 3:53 
QuestionHow to use Screen Event Recorder DLL in VB or VBA Pinmembersteventoh13-Oct-10 2:11 
GeneralImpressive PinmemberDr.Luiji11-Dec-08 20:56 
GeneralVista PinmemberB4stard9-Aug-07 16:29 
QuestionTime Moves On PinmemberFinbar18-Feb-07 10:59 
AnswerRe: Time Moves On PinmemberErnest Laurentin18-Feb-07 11:15 
QuestionRe: Time Moves On PinmemberFinbar18-Feb-07 11:48 
AnswerRe: Time Moves On Pinmemberftas25-Jun-07 4:48 
GeneralExcellent, but have you a release based also on windows event Pinmembersnoopy246623-Aug-06 23:55 
This DLL is verry efficient;) but do you have a release based on windows event. If you change screen resolution script doesn't work anymore Sigh | :sigh:
Thanks.

Generalbuilding media player Pinmembersumitgupta2219-Jan-06 0:51 
GeneralRe: building media player PinmemberErnest Laurentin19-Jan-06 14:20 
GeneralSome issues PinmemberRussianDevil18-Jul-05 16:05 
GeneralHelp no actions with keyboard and mouse Pinmemberromedenne17-Nov-04 9:24 
QuestionMacRcrd.vcproj missing? Pinmembermaciejkromrych@poczta.onet.pl6-Jun-04 23:35 
AnswerRe: MacRcrd.vcproj missing? Pinmembermaciejkromrych@poczta.onet.pl7-Jun-04 1:31 
GeneralAutomatic test framework for gui Pinmemberwinecad6-Apr-04 12:59 
Generalcreating mfc event dll PinmemberXins10-Mar-04 16:54 
QuestionHow can I Debug using RunDll32.exe PinmemberAisha Ikram17-Nov-03 18:28 
AnswerRe: How can I Debug using RunDll32.exe PinmemberErnest Laurentin20-Nov-03 17:44 
GeneralSimply genial Pinmemberleirbagz5-Oct-03 0:10 
GeneralRe: Simply genial PinmemberErnest Laurentin5-Oct-03 18:39 
GeneralDon't run! Pinmembernikouhl20-Sep-03 12:05 
GeneralRe: Don't run! PinmemberAisha Ikram13-Nov-03 20:17 
GeneralRe: Don't run! PinmemberErnest Laurentin14-Nov-03 19:55 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 10 May 2003
Article Copyright 2003 by Ernest Laurentin
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid