473,472 Members | 2,181 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Windows messages between a console application and unmanaged DLL

Hi,

Currently, I have a console application written in C# and an unmanaged
legacy DLL written in VC++ 6.0. In the DLL's previous application, when an
event occurs in the DLL, a windows message would be sent to the host GUI
application via PostMessage to WM_USER + X. The GUI application would then
execute a function to retrieve data from the DLL.

With this new setup, I have a console application as the host. I retrieved
the handle for the console application using System.Runtime.InteropServices
and sent it to the DLL. When an event occurs, a windows message should be
sent to the console application from the DLL thus executing a function to
retrieve data from the DLL. Is this old method possible in .net or is there
a new and better way to do it? I haven't been able to figure it out. What
do I need to implement to receive the windows message in the console
application? Also, eventually, the console application will be converted to
a windows service. Will the windows message capture work in there as well?

Thanks for your time and insight,

Chris
Nov 13 '05 #1
2 10960
Chris,

I think that using WM_USER + X is a bad idea. If anything, you should
name it by calling RegisterWindowMessage and then use the message code
returned from that.

This method is not possible because it is a console application.
Consoles don't have message loops.

The service could use the message loop, but I don't really know if it is
a good idea. You would probably have to select "allow service to interact
with desktop" and then on top of that, you would have to run a message pump
in the OnStart method (which would never return, since it is in the OnStart
method), and I don't know if that is a good idea.

I would find another way of getting information into your service. I
would use remoting, or something like that instead of a windows message.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Chris" <c w a n @ n o s p a m - v i g i l . c o m> wrote in message
news:ev**************@TK2MSFTNGP10.phx.gbl...
Hi,

Currently, I have a console application written in C# and an unmanaged
legacy DLL written in VC++ 6.0. In the DLL's previous application, when an event occurs in the DLL, a windows message would be sent to the host GUI
application via PostMessage to WM_USER + X. The GUI application would then execute a function to retrieve data from the DLL.

With this new setup, I have a console application as the host. I retrieved the handle for the console application using System.Runtime.InteropServices and sent it to the DLL. When an event occurs, a windows message should be
sent to the console application from the DLL thus executing a function to
retrieve data from the DLL. Is this old method possible in .net or is there a new and better way to do it? I haven't been able to figure it out. What do I need to implement to receive the windows message in the console
application? Also, eventually, the console application will be converted to a windows service. Will the windows message capture work in there as well?
Thanks for your time and insight,

Chris

Nov 13 '05 #2
Hi Nicholas,

I figured it would be a bad idea ...

Is it possible to do remoting from a C++ DLL? Also, what other alternatives
might there be?

Thanks
"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:%2****************@TK2MSFTNGP12.phx.gbl...
Chris,

I think that using WM_USER + X is a bad idea. If anything, you should
name it by calling RegisterWindowMessage and then use the message code
returned from that.

This method is not possible because it is a console application.
Consoles don't have message loops.

The service could use the message loop, but I don't really know if it is a good idea. You would probably have to select "allow service to interact
with desktop" and then on top of that, you would have to run a message pump in the OnStart method (which would never return, since it is in the OnStart method), and I don't know if that is a good idea.

I would find another way of getting information into your service. I
would use remoting, or something like that instead of a windows message.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Chris" <c w a n @ n o s p a m - v i g i l . c o m> wrote in message
news:ev**************@TK2MSFTNGP10.phx.gbl...
Hi,

Currently, I have a console application written in C# and an unmanaged
legacy DLL written in VC++ 6.0. In the DLL's previous application, when an
event occurs in the DLL, a windows message would be sent to the host GUI
application via PostMessage to WM_USER + X. The GUI application would

then
execute a function to retrieve data from the DLL.

With this new setup, I have a console application as the host. I

retrieved
the handle for the console application using

System.Runtime.InteropServices
and sent it to the DLL. When an event occurs, a windows message should be sent to the console application from the DLL thus executing a function to retrieve data from the DLL. Is this old method possible in .net or is

there
a new and better way to do it? I haven't been able to figure it out.

What
do I need to implement to receive the windows message in the console
application? Also, eventually, the console application will be

converted to
a windows service. Will the windows message capture work in there as

well?

Thanks for your time and insight,

Chris


Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Max | last post by:
Hi All, I am developing an application that needs to run in one of two modes: 1. If No command line param is provided the application should run as Window form. 2. If command line param is...
1
by: Artur Kowalski | last post by:
I have a NotifyIcon in my Windows Service project and I am trying to add a ContextMenu to this NotifyIcon or use some of the mouse events. Everything isn't working. I think so base class of the...
2
by: Bob Rock | last post by:
Hello, does anyone know why standard .NET console or windows applications that do nothing start out with a minimum of 3 threads??? Aren't 3 threads far to many for an application that does...
3
by: Javaman59 | last post by:
I've spent the last 3 years programming VC++, and learnt that Windows programming is all about messages. Now I'm doing C#, and there isn't a windows message to be seen! Now, I don't miss those...
3
by: Gustavo L. Fabro | last post by:
Greetings! I'm a newbie in Visual C++ .NET (have programmed in Borland C++ and Builder for long) and I am trying to do a very simple thing, but I'm stuck. I created an (unmanaged) DLL project...
8
by: RTT | last post by:
i'm writing a windows form but codebased a iwant to run the code as a different user. like in a webapplication you can impersonate a user so the website does not run on the standard ASP.NET...
6
by: Giojo | last post by:
Hello guys! I can't resolve this problem.. I want my programm in c# working with only console if there are some parameters, but if someone make double-click on the exe I want to start the graphic...
1
by: lavu | last post by:
I currently have a C# windows Application . I would like this App to work through an command line interface also. I would like to specify command line params, which should start the app and process...
4
by: Peter Nimmo | last post by:
Hi, I am writting a windows application that I want to be able to act as if it where a Console application in certain circumstances, such as error logging. Whilst I have nearly got it, it...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.