Solved

Sending message to C# application from C++ DLL

Posted on 2003-12-11
4
470 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

11 Experts available now in Live!

Get 1:1 Help Now