Autor Beitrag
Mitmischer 1703
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 754
Erhaltene Danke: 19

Win 7, Debian
Delphi Prism, Delphi 7, RAD Studio 2009 Academic, C#, C++, Java, HTML, PHP
BeitragVerfasst: Mi 02.03.11 22:52 
Hi DF!

ich habe ein Problem mit der IPC zwischen C# und C++. Ich starte aus meinem C#-Programm den C++-Client und erzeuge im C++ ein Nachrichtenfenster, welches auch funktioniert (ich erhalte nach dem erzeugen 3 Nachrichten). Dieses will ich in C# finden, jedoch wird mir als Handle stets 0 zurückgegeben:

Hier der Code des C++-Clients:
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
const char* hiddenWindowName = "ka";

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    //incoming...
    cout << "yeah, man!" << endl;
    return 0;
}
int go()
{
    WNDCLASSEX wcex;
    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.lpfnWndProc  = WndProc;
    wcex.lpszClassName = hiddenWindowName;

    wcex.style           = CS_HREDRAW | CS_VREDRAW;
    wcex.cbClsExtra      = 0;
    wcex.cbWndExtra      = 0;
    wcex.hInstance      = GetModuleHandle(NULL);
    wcex.hIcon           = NULL;
    wcex.hCursor           = NULL;
    wcex.hbrBackground = NULL;
    wcex.lpszMenuName  = NULL;
    wcex.hIconSm           = NULL;

    if ((RegisterClassEx(&wcex) == 0))
        cout << "FAIL!" << endl;


    CreateWindowEx(NULL, hiddenWindowName, hiddenWindowName, NULL, 00000, NULL, wcex.hInstance, NULL);
}

Und hier das C#-Programm:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
                Process P = new Process();
                P.StartInfo.FileName = PATH;
                P.StartInfo.Arguments = "-client";
                P.Start();                
                //hwnd = P.Handle.ToInt32();
                hwnd = Win32.FindWindow(null"ka");
                MessageBox.Show(hwnd.ToString());
                Win32.SendMessage(hwnd, 100);


Moderiert von user profile iconKha: Tags repariert.

_________________
Die Lösung ist nicht siebzehn.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 02.03.11 23:57 
Wie wäre es, wenn du dir einmal die Parameter von FindWindow anschaust? Wo steht da nochmal der Klassenname? ;-)
msdn.microsoft.com/e...633499(v=vs.85).aspx
Ich habe die Erfahrung gemacht, dass man oft Fenster ohne den Klassennamen nicht findet. Und hier ist der ja eh gleich dem Fensternamen. Also warum übergibst du null?

Für diesen Beitrag haben gedankt: Mitmischer 1703
Mitmischer 1703 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 754
Erhaltene Danke: 19

Win 7, Debian
Delphi Prism, Delphi 7, RAD Studio 2009 Academic, C#, C++, Java, HTML, PHP
BeitragVerfasst: Do 03.03.11 14:00 
Hi!

Ich habe jetzt mal in beiden Parametern "ka" übergeben, leider bleibt mein Handle 0.

_________________
Die Lösung ist nicht siebzehn.
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Do 03.03.11 15:13 
Ich würde behaupten, zu dem Zeitpunkt existiert das Handle einfach noch nicht. Vielleicht wäre eine der anderen IPC-Methoden geschickter.

_________________
>λ=
Mitmischer 1703 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 754
Erhaltene Danke: 19

Win 7, Debian
Delphi Prism, Delphi 7, RAD Studio 2009 Academic, C#, C++, Java, HTML, PHP
BeitragVerfasst: Sa 05.03.11 09:55 
Hallo!

ich weiß zwar nicht, warum es jetzt geht, aber meine WndProc war schuld! CreateWindow hat mir ein NULL zurückgeliefert und GetLastError auch. Da hab ich dann nachgeschlagen, ob meine WndProc irgendetwas besonderes zurückgeben muss und tätsächlich :

ausblenden C#-Quelltext
1:
 return DefWindowProc(hWnd, message, wParam, lParam);					


Ab jetzt habe ich auch ein waschechtes Fenster bekommen und kann es über meinen Client finden.

Danke für eure Mühe!

_________________
Die Lösung ist nicht siebzehn.