473,385 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C# messaging

GTi
Do anyone have a simple solution how I can send a simple message (int)
from a C program to a C# program/service ?
Preferred both ways C <-> C#

(Windows messages - how ?)

It must be extremely easy and in-memory (no disk media).

Best regards,
Newbie GTi
Nov 17 '05 #1
4 2978
Is your C program Windows based or DOS based?

If both the C and C# are Windows based (they create a window) you can send
and receive regular windows messages between the 2 applications using
SendMessage().

If your C program is DOS based, you may be able to launch it as a child
process from your C# program and redirect it’s STDIN and STDOUT to send and
receive text from it.

Hope this helps.
Regards,
DlgProc

"GTi" wrote:
Do anyone have a simple solution how I can send a simple message (int)
from a C program to a C# program/service ?
Preferred both ways C <-> C#

(Windows messages - how ?)

It must be extremely easy and in-memory (no disk media).

Best regards,
Newbie GTi

Nov 17 '05 #2
GTi
Sorry, didn't mention that.
Both are windows applications.
(C# will not be a win service)

I was thinking of windows messages (SendMessage)
But how is this in C#? Unable to find any doc about it.
Sending, receiving messages.
RegisterWindowMessage() i C#

[DllImport("user32.dll")]
int RegisterWindowMessage(????? lpString);
What should be used instead of LPCTSTR?
"dlgproc" <dl*****@discussions.microsoft.com> skrev i melding
news:4D**********************************@microsof t.com...
Is your C program Windows based or DOS based?

If both the C and C# are Windows based (they create a window) you can send
and receive regular windows messages between the 2 applications using
SendMessage().

If your C program is DOS based, you may be able to launch it as a child
process from your C# program and redirect it's STDIN and STDOUT to send
and
receive text from it.

Hope this helps.
Regards,
DlgProc

"GTi" wrote:
Do anyone have a simple solution how I can send a simple message (int)
from a C program to a C# program/service ?
Preferred both ways C <-> C#

(Windows messages - how ?)

It must be extremely easy and in-memory (no disk media).

Best regards,
Newbie GTi

Nov 17 '05 #3
You can use a string there instead of LPCTSTR in C#.

[DllImport("user32.dll")]
public static extern int RegisterWindowMessage(string lpString);

The string you specify here needs to be a unique string in the Windows
environment so that you can differentiate your message from any other Window
message.

So in your C app, call RegisterWindowMessage(“MY MESSAGE NAME HERE”) You
will get an int returned to you so save it.

In your C# app call RegisterWindowMessage(“MY MESSAGE NAME HERE”) (you MUST
use the same exact string as you did in your C app). You will get an int
returned to you so save it.

The ints you get in your C app and your C# app will be the exact same
number. This number will probably change the next time you boot Windows so
don’t hard code it.

Now you can send your unique message between your 2 apps specifying the int
you got from calling RegisterWindowMessage as the message number in
SendMessage();

Put the numeric data you want to send back and forth between your 2 apps in
the wParam or lParam parameters of SendMessage() and you’re on your way.

The other thing you need to do is determine how each app is going to find
the window handle of the other app so it can send the message to it. You can
do this one of 2 ways:

First way:
Hard code the window class and window caption (title bar text) of the other
app in your app and use FindWindow() to get the window handle. (easy but
crude)

Second way:
Create another message using RegisterWindowMessage. Post this message as a
broadcast message (set hWnd in PostMessage to 0). All windows on the system
will get your message. If an app doesn’t recognize your message, it will
ignore it. But you will set up your other App to recognize it. When posting
this message, put the handle to the window in lParam. Now when your other app
gets the broadcast message, it can get the hWnd of the sender. Now you can
send the same message back to the sender with receiver’s hWnd. Now both apps
have the window handle to the partner and you can start communicating.

Best of luck.
DlgProc

"GTi" wrote:
Sorry, didn't mention that.
Both are windows applications.
(C# will not be a win service)

I was thinking of windows messages (SendMessage)
But how is this in C#? Unable to find any doc about it.
Sending, receiving messages.
RegisterWindowMessage() i C#

[DllImport("user32.dll")]
int RegisterWindowMessage(????? lpString);
What should be used instead of LPCTSTR?
"dlgproc" <dl*****@discussions.microsoft.com> skrev i melding
news:4D**********************************@microsof t.com...
Is your C program Windows based or DOS based?

If both the C and C# are Windows based (they create a window) you can send
and receive regular windows messages between the 2 applications using
SendMessage().

If your C program is DOS based, you may be able to launch it as a child
process from your C# program and redirect it's STDIN and STDOUT to send
and
receive text from it.

Hope this helps.
Regards,
DlgProc

"GTi" wrote:
Do anyone have a simple solution how I can send a simple message (int)
from a C program to a C# program/service ?
Preferred both ways C <-> C#

(Windows messages - how ?)

It must be extremely easy and in-memory (no disk media).

Best regards,
Newbie GTi


Nov 17 '05 #4
GTi
Thanks dlgproc,
Put the numeric data you want to send back and forth between your 2 apps
in
the wParam or lParam parameters of SendMessage() and you're on your way.
But what about if the C APP needs to send message to my C# app?
How can I wait/recieve Windows Messages in my C# app?
There is no GetMessage in C# (as I know of)....

"dlgproc" <dl*****@discussions.microsoft.com> wrote in message
news:10**********************************@microsof t.com... You can use a string there instead of LPCTSTR in C#.

[DllImport("user32.dll")]
public static extern int RegisterWindowMessage(string lpString);

The string you specify here needs to be a unique string in the Windows
environment so that you can differentiate your message from any other
Window
message.

So in your C app, call RegisterWindowMessage("MY MESSAGE NAME HERE") You
will get an int returned to you so save it.

In your C# app call RegisterWindowMessage("MY MESSAGE NAME HERE") (you
MUST
use the same exact string as you did in your C app). You will get an int
returned to you so save it.

The ints you get in your C app and your C# app will be the exact same
number. This number will probably change the next time you boot Windows so
don't hard code it.

Now you can send your unique message between your 2 apps specifying the
int
you got from calling RegisterWindowMessage as the message number in
SendMessage();

Put the numeric data you want to send back and forth between your 2 apps
in
the wParam or lParam parameters of SendMessage() and you're on your way.

The other thing you need to do is determine how each app is going to find
the window handle of the other app so it can send the message to it. You
can
do this one of 2 ways:

First way:
Hard code the window class and window caption (title bar text) of the
other
app in your app and use FindWindow() to get the window handle. (easy but
crude)

Second way:
Create another message using RegisterWindowMessage. Post this message as a
broadcast message (set hWnd in PostMessage to 0). All windows on the
system
will get your message. If an app doesn't recognize your message, it will
ignore it. But you will set up your other App to recognize it. When
posting
this message, put the handle to the window in lParam. Now when your other
app
gets the broadcast message, it can get the hWnd of the sender. Now you can
send the same message back to the sender with receiver's hWnd. Now both
apps
have the window handle to the partner and you can start communicating.

Best of luck.
DlgProc

"GTi" wrote:
Sorry, didn't mention that.
Both are windows applications.
(C# will not be a win service)

I was thinking of windows messages (SendMessage)
But how is this in C#? Unable to find any doc about it.
Sending, receiving messages.
RegisterWindowMessage() i C#

[DllImport("user32.dll")]
int RegisterWindowMessage(????? lpString);
What should be used instead of LPCTSTR?
"dlgproc" <dl*****@discussions.microsoft.com> skrev i melding
news:4D**********************************@microsof t.com...
> Is your C program Windows based or DOS based?
>
> If both the C and C# are Windows based (they create a window) you can
> send
> and receive regular windows messages between the 2 applications using
> SendMessage().
>
> If your C program is DOS based, you may be able to launch it as a child
> process from your C# program and redirect it's STDIN and STDOUT to send
> and
> receive text from it.
>
> Hope this helps.
> Regards,
> DlgProc
>
> "GTi" wrote:
>
>> Do anyone have a simple solution how I can send a simple message (int)
>> from a C program to a C# program/service ?
>> Preferred both ways C <-> C#
>>
>> (Windows messages - how ?)
>>
>> It must be extremely easy and in-memory (no disk media).
>>
>> Best regards,
>> Newbie GTi
>>
>>
>>


Nov 17 '05 #5

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

Similar topics

1
by: lawrence | last post by:
What is the PHP equivalent of messaging, as in Java?
2
by: Dennis Owens | last post by:
I want to develop a Client/Server messaging system that does not require Microsoft messaging. I want to use the .Net remoting, but I am having some real problems with the remoting. The remoting...
0
by: Dennis Owens | last post by:
Read below for previous conversation. We are developing an application that will some day run on anything from a computer down to a PDA (this is were the Lightweight comes in). The messaging...
1
by: ptdaw | last post by:
After spending a little time reading the documentation, I attempted to add some messaging code to my VB.Net project, only to discover that I couldn't get past my Imports System.Messaging ...
3
by: Lex Luthor | last post by:
Please i am looking for a instant messaging like msn or icq for my site in asp.. (a chat system but like instant messaging for my site) please help me..
3
by: Peter | last post by:
Hello, Thanks for reviewing my quesiton. What does a website need in order to send text messaging to cell phones? Is this something the hosting company will offer or does the website need...
1
by: John A Grandy | last post by:
in .NET 2.0 where is the type Message located ? in .NET 1.1 it was System.Messaging.Message
4
by: John Grant | last post by:
If I build a web services today with VS 2005 does it support reliable messaging? If I use WSE 3.0 will it support reliable messaging? If I don’t have reliable messaging can I make a web method...
1
by: Anthony J. Biondo Jr. | last post by:
Hi Everyone: I was wondering if it is common practice to use some sort of messaging (MSMQ, WebSphere MQ) with web services. I understand the need for messaging for insert / update transactions,...
2
by: jparulan | last post by:
Hi All, I am developing web service that does not use IIS, I was successful on deploying a normal web service with System.Data and System.Web namespaces. BUT when I added the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.