Recent

Author Topic: Anyone know the protocol to connect to TSimpleIPCServer from c# client?  (Read 17437 times)

evoshroom

  • Full Member
  • ***
  • Posts: 157
Re: Anyone know the protocol to connect to TSimpleIPCServer from c# client?
« Reply #15 on: January 19, 2013, 07:03:54 pm »
Was out for most of the morning and just had a chance to review the source.  Yeah, so TSimpleIPCClient just uses standard API calls on Windows but it has some hardcoded assumptions that make having it communicate cross-language a little annoying.

Namely it connects through this procedure:

Code: [Select]
procedure TWinMsgClientComm.Connect;
begin
  FHWND:=FindWindow(MsgWndClassName,PChar(FWindowName));
  If (FHWND=0) then
    Owner.DoError(SErrServerNotActive,[Owner.ServerID]);
end;

You see FindWindow only has two parameters: The Window Class and the Window Name.  The window name is easy to modify in any language, including C#.  However, the Window Class is hard to modify in many languages.  From reading elsewhere, I believe the Window Name ends up corresponding to the TSimpleIPCClient.ServerID.  However there is no corresponding property for the Window Class.  It is hardcoded in simpleipc.inc as:

Code: [Select]
Const
  MsgWndClassName : pchar = 'FPCMsgWindowCls';

So most of the challenge is coding a window in another language with a custom class name which is then set to 'FPCMsgWindowCls'. 

Really, it sort of almost makes more sense long term to change the SimpleIPCClient to add a new property for 'LanguageID' or something and set it to FPCMsgWindowCls by default, so it can be more easily adapted to talking to other languages.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Anyone know the protocol to connect to TSimpleIPCServer from c# client?
« Reply #16 on: January 19, 2013, 08:47:16 pm »
So most of the challenge is coding a window in another language with a custom class name which is then set to 'FPCMsgWindowCls'. 

Really, it sort of almost makes more sense long term to change the SimpleIPCClient to add a new property for 'LanguageID' or something and set it to FPCMsgWindowCls by default, so it can be more easily adapted to talking to other languages.
Ok, thanks.

Haven't looked at the source code - but:
1. I wonder if manipulating a form class name in .Net maps to the class name the FPC client wants (presumably some kind of Windows API construct).
2. Are you talking about the FPC version, not a Lazarus version of the simple IPC client? I'm wondering whether Lazarus adds some Windows API sauce to look up the server etc.

As I said, I haven't looked at the ipc server source, which I really should if I was to give more definitive answers but perhaps this is food for thought...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

evoshroom

  • Full Member
  • ***
  • Posts: 157
Re: Anyone know the protocol to connect to TSimpleIPCServer from c# client?
« Reply #17 on: January 19, 2013, 08:54:54 pm »
Code: [Select]
2. Are you talking about the FPC version, not a Lazarus version of the simple IPC client? I'm wondering whether Lazarus adds some Windows API sauce to look up the server etc.
Again, source is here: http://code.google.com/p/upas/source/browse/trunk/3rd/fpc/fcl-process/src/simpleipc.inc?r=11

Lazarus is looking up the window handle using FindWindow().  FindWindow() *is* WinAPI.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Anyone know the protocol to connect to TSimpleIPCServer from c# client?
« Reply #18 on: January 20, 2013, 09:52:31 am »
Yes, or here:
http://svn.freepascal.org/svn/fpc/trunk/packages/fcl-process/src/win/simpleipc.inc

"Lazarus is looking up the window handle using FindWindow().  FindWindow() *is* WinAPI."
Yes, I was wondering whether this usage of windows handles was in the FPC part or in the Lazarus wrapper. Having looked it's in the FPC part (as you already know).

Don't know if you've found/linked this already but the second answer in this page looks promising:
http://stackoverflow.com/questions/128561/registering-a-custom-win32-window-class-from-c-sharp
(Note: there might be a much easier way, perhaps your attempt at specifying a custom class name would be enough perhaps not)

I'll leave others to help here, my .Net knowledge has run out.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified