Solved

Sending message to C# application from C++ DLL

Posted on 2003-12-11
4
467 Views
Last Modified: 2011-09-20
I have a C++ Win32 DLL that gets called by Winlogon.exe whenever a user locks and unlocks the PC. So, whenever a user locks the computer Winlogon.exe calls a function in my DLL.
Now, the whole purpose is to have my C# application react on those events.
So how do I send a message to the C# application (which will be running) from the C++ DLL?
This is part 2 of a 3-part question :) For part 1 see:
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20819936.html

Since this is C# section, I’ll also accept comments that answer just C# part, and I’ll post the C++ part in C++ section if needed.

Thanks,
Alex
0
Comment
Question by:astankovic
4 Comments
 
LVL 11

Assisted Solution

by:Agarici
Agarici earned 100 total points
ID: 9921289
you could just send a message to the window of your c# app. some user defined message
the handle of the c# form is easy to obtain, how to have it in the dll? export a funtion from that dll, a function that sets the value of a HWND variable in the dll and call that function from your c# app as it starts.

hope this helps.

A.
0
 
LVL 4

Author Comment

by:astankovic
ID: 9922522
Ok, I see what you are saying.
But how do I "listen" for that message in C#? What class would I use?
Could you provide me with a link where I can see some sample code?

Thanks,
Alex
0
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 100 total points
ID: 9926200
0
 
LVL 5

Accepted Solution

by:
jjacksn earned 300 total points
ID: 9926843
astankovic,

you want to override WndProc

protected override void WndProc(ref Message aMessage)
{
      if(aMessage.Msg == myCustomMessage1)
      {
                         //Do something
      }
               base.WndProc(ref aMessage);
}

this will trap all messages sent to the form.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now