The MEDriver sample illustrates the use of COM events (fired from an unmanaged COM server) through a .NET Framework wrapper, automatically generated from the COM server's type library.
MEDriver is implemented as a Windows Forms application. It uses the ATL sample IRandom and source interface IRandomEvent through CoRandom and IRandomEvent_FireEventHandler as if it was a .NET Framework event. The application creates multiple sinks to the Fire event of class CoRandom and controls the threads that the server creates.
| Security Note |
|---|
This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. |
Building and Running the Sample
To build and run MEDriver using Visual Studio
In the Visual Studio IDE, load the solution file MEDriver.sln.
In Solution Explorer, right-click the MEDriver solution.
On the shortcut menu, click Build Solution.
On the Debug menu, click Start.
When you run MEDriver.exe, click the Start button at least once, and then click the Advise button several times. Each click of the Advise button adds a sink to the Fire event, which makes the display wider. If you do not click the Advise button, you will not see any activity in the display.
Keywords
This sample demonstrates the following keywords:
Control::CreateGraphics; Control::ClientRectangle; Graphics::DrawLine; Color::FromArgb; Mutex::WaitOne; Mutex::ReleaseMutex; Hashtable::Item; Application::Run; Button::Location; Button::Size; Button::Text; ControlCollection::AddRange