?
Solved

Sending message to C# application from C++ DLL

Posted on 2003-12-11
4
Medium Priority
?
484 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 11

Assisted Solution

by:Agarici
Agarici earned 400 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 400 total points
ID: 9926200
0
 
LVL 5

Accepted Solution

by:
jjacksn earned 1200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

777 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