Re: C# messaging



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: LogonUser()
    ... // This sample can be run only on Windows XP. ... String lpszPassword, ... int dwLogonType, int dwLogonProvider, ref IntPtr phToken); ... private unsafe static extern int FormatMessage(int dwFlags, ref IntPtr ...
    (microsoft.public.dotnet.security)
  • Re: Validating a user using SSPI
    ... > My problem is trying to authenticate using windows ... Here's some code that you can use: [warning: untested air code] ... static extern int LogonUser(string Username, string Domain, string Password, ...
    (microsoft.public.dotnet.security)
  • Crypto API problem while using forms authentication
    ... instead of integrated windows authentication because i don't like this pop ... public static extern int LogonUser(String lpszUserName, ... String lpszPassword, ... protected TextBox txtUserName; ...
    (microsoft.public.dotnet.security)
  • Crypto API problem while using forms authentication
    ... instead of integrated windows authentication because i don't like this pop ... public static extern int LogonUser(String lpszUserName, ... String lpszPassword, ... protected TextBox txtUserName; ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Maximizing and bringing another process main window on top
    ... We have an app which must be single instance. ... check if it is already running (using the Process object in the ... the already started application and bring it on top of other windows. ... public static extern int SendMessage(int hWnd, uint Msg, int wParam, ...
    (microsoft.public.dotnet.general)