Re: C# messaging



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" <dlgproc@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:10A96F18-166C-4376-99C8-1AE90172BE3D@xxxxxxxxxxxxxxxx
> 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" <dlgproc@xxxxxxxxxxxxxxxxxxxxxxxxx> skrev i melding
>> news:4D8E9D17-D8B7-4862-9630-C7402C672CA4@xxxxxxxxxxxxxxxx
>> > 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
>> >>
>> >>
>> >>
>>
>>
>>


.



Relevant Pages

  • Re: C# messaging
    ... The string you specify here needs to be a unique string in the Windows ... will get an int returned to you so save it. ... use the same exact string as you did in your C app). ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Windows.. its like coming home!
    ... gradual transition, especially in going from OS 9 to OS X. ... They needed something that could compete with Windows, ... mean by the "2 of every app" comment before - Apple took whatever apps ... I've found that because the Dock shows applications rather than windows, ...
    (comp.sys.mac.advocacy)
  • Re: Windows.. its like coming home!
    ... gradual transition, especially in going from OS 9 to OS X. ... They needed something that could compete with Windows, ... mean by the "2 of every app" comment before - Apple took whatever apps ... I've found that because the Dock shows applications rather than windows, ...
    (comp.sys.mac.advocacy)
  • RE: Beginners Questions
    ... We do use Windows form on the presentation layer which is on ... terminal server and call web services on the business logic side. ... of using "proxy" authentication on SQL Server. ... > I have written an app with a Windows Forms UI that is deployed to clients ...
    (microsoft.public.dotnet.distributed_apps)
  • Re: Frustration level with Windows -- ARG!
    ... I can have an app sieze and you can go take a ten ... That is MS-Outlook, not Windows. ... to the processes tab, not the applications tab. ... and it tries to stop them "gently" if it can, before resorting to kill -9. ...
    (comp.sys.mac.advocacy)