Solved

Sending message to C# application from C++ DLL

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

789 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