Is it possible to send an RCV20 command from an XP to the "main program"?

Best Answers

Answers

  • MonsenMonsen Administrator 🖼️ 51 images Cartographer

    That's an interesting thought. I don't see why not, but I've never tried it. To be honest, I've never written anything using intercom myself, so I won't be able to be much help here.

    Don't know of any examples for that either unfortunately. Maybe @saunderl have an idea if he is around.

  • At first, thank you, Remy, and thank you, Sue, Ralf, Quenten and all the others for your great work in this great forum!!!!


    I have tried a lot with the intercom.dll. You can easily send RCV20 commands from a C# program.

    The problem is connection establishment via intercom to the started CC3+ instance. This works sometimes and sometimes not, and I do not know why.

    If you would have your own XP, it would be connected immediately after starting CC3 and then such errors would not occur?

    What I want is a query of all entities à la "Walking the Drawing List" from your tutorial https://rpgmaps.profantasy.com/developing-add-ons-for-cc3-part-2-entity-basics/ and then send RCV20 commands from a C# program with a XP.dll in c++.

  • MonsenMonsen Administrator 🖼️ 51 images Cartographer

    In my very limited intercom experience, problems connecting usually happens if you have two instances of CC running.

    Embedding it in an XP won't solve this, because there still wouldn't be a way to connect it to the same CC3 instance as the XP belongs to, there is no link there.

    If you are trying to manipulate entities, it might be better to just do everything from inside the XP instead of going through intercom.

  • I think I have a problem understanding this. I did not know that the RCV20 command requires intercom. In my opinion it works from macros as well. So this must be some kind of built-in "meta-"command?

    I find the manipulation of entities with the normal XP-C methods quite complicated. Is there actually a manual for this? (Maybe even for the "old" original FastCad-XP). I can't deduce enough from the few examples of your tutorial and a few single example programs of others. Especially since I am not a big expert for C++ ... 

  • jslaytonjslayton Moderator, ProFantasy Mapmaker
    edited October 2020

    First, what are RCV20 commands?

    There are a lot of things that can go wrong with the Intercom system. It's a point-to-point communication system and can only have one program at each attachment point. If you start up another instance of either program, things can go badly. If you're lucky, it will just fail to connect.

    If either program in an Intercom conversation crashes while the interface is active, that still counts as having an active instance until you reboot your system. If you stop a program in the debugger while the interface is open, that counts as an active instance until you reboot your system.

    If you want to use Intercom, I recommend implementing an icReset program that wipes the 4K memory block named "$INTERCOM$". Don't use it while any instances are active, but it's a way to pretend that the system hasn't had bad things happen to it. Some untested code:

    void icReset()
    {
     HANDLE hInterCom = CreateFileMapping((void*) 0xFFFFFFFF, NULL, 
      PAGE_READWRITE, 0, 4096, "$INTERCOM$");
     if (hInterCom)
     {
      char* pBfr = (char*) MapViewOfFile(hInterCom, FILE_MAP_ALL_ACCESS, 0, 0, 4096);
      if (pBfr)
      {
       memset(pBfr, 0, 4096);
       UnmapViewOfFile(pBfr);
      }
      CloseHandle(hInterCom);
     }
    }
    


  • Thank you!

    But "actually" I did not want to use intercom at all. Exactly because of the problems you described with "hanging" instances. I wanted to write an XP that can send RCV20 commands. Completely WITHOUT intercom. Is that possible? 

  • MonsenMonsen Administrator 🖼️ 51 images Cartographer
    edited October 2020

    RCV20 is just a macro with a single line, RCVDATA, in it. RCVDATA is a variable holding data sent to CC3+ via intercom. I guess you can populate this variable manually and then call the macro, but it is really a special macro made to handle intercom requests that are CC3+ commands.

    The available documentation is the .pdf that comes with the XP toolkit. It is old and incomplete, but that's what is.

    As for using C# from an XP, that is actually possible. @saunderl did once write a tutorial about that, but the site is no longer available and the wayback machine don't seem to have captured the actual tutorials. I've been considering looking into that myself, when time permits, but it is fairly low down on my priority list.

    Loopysue
  • I thought an XP could go the shorter way WITHOUT intercom, it is already in the same process room.

  • MonsenMonsen Administrator 🖼️ 51 images Cartographer
    Accepted Answer

    Sure. You don't need intercom at all. But then you wouldn't really be dealing with RCV20 either. RCV20 sole purpose is for running commands received over intercom.

  • jslaytonjslayton Moderator, ProFantasy Mapmaker
    edited October 2020

    Ah, I see. It's not a matter of being in the same process or not. It's a matter of being able to call back and forth between the programs. The features provided to make Intercom work are composed of several smaller primitive. You should be able to use C# interop features to call into a few native C++ routines that do the ugly parts. Things that the C++ code might want to wrap:

    SetVar(char *pLabel, char *pValue) sets a variable to a string. This is used to set the RCVDATA variable in what you're looking for.

    MacroCmdChk() executes the macro command string specified in esi (you'll need to stuff esi to point at the string yourself - __asm works here). This one is the heart of the RCV* communications channel.

    Note that if you're doing native C++ development rather than C#, you'd probably do better to just call the native routines directly.

    What problem are you trying to solve that requires an XP?

  • Sounds very interesting, but is unfortunately beyond my C (and ASM!) capabilities. Thanks for the explanation anyway!

  • jslaytonjslayton Moderator, ProFantasy Mapmaker
    edited October 2020

    [20201009 edited to correct spelling mistake from MacroChkCmd to MacroCmdChk]

    a quick (untested) wrapper for MacroChkCmd might look like:

    int MacroCmdChk2 (char* cmd)
    {
        int result;
        __asm mov esi, cmd
        __asm call MacroCmdChk 
        __asm xor eax,eax
        __asm adc eax,0  
        __asm mov result, eax
        return result;
    }
    

    I'm not sure if that's helpful in any way, though.

    MapjunkieLoopysue
  • Accepted Answer

    Thanks a lot! I will try it out.

  • I can't find a declaration for MacroChkCmd in the header files for XP.

    What should the header entry look like?


    int _stdcall MacroChkCmd();   

    or

    int XPCALL MacroChkCmd();

    are not accepted by the linker.

  • jslaytonjslayton Moderator, ProFantasy Mapmaker
    edited October 2020

    Sorry about that. It should be MacroCmdChk instead of MacroChkCmd (I got it right in the original post, but transposed the name in the code sample). The signature should look like

    int XPCALL MacroCmdChk();

    as you had surmised. I'll go back and edit the earlier posts to fix that in case anyone happens to look there. I don't have any way to test compile those on my system at the moment because I don't have the basic XP dev system (mine has a bunch of other things on it that get in the way).

    Also, I think that Monsen has a copy of a newer dev kit available somewhere.

  • jslaytonjslayton Moderator, ProFantasy Mapmaker

    The code for the Campaign Mapper intercom receive command pretty much looks like:

    void doCommand(int msgId, char* str)
    {
      char cmdName[64];
      sprintf(cmdName, "RCV%d", msgId)
      SetVar("RCVDATA", str);
      if (!MacroCmdChk(cmdName))
      {
        MessageBox(NULL, cmdName, "Message received from Core Rules II", MB_OK);
      }
    }
    
    LoopysueJimPMapjunkie
  • NOW IT WORKS!!!!!

    Thank you very much!

  • Quick and Dirty example: Take first code example from

    https://rpgmaps.profantasy.com/developing-add-ons-for-cc3-part-1-getting-started/  

    Change function

    void XPCALL About() { ... }


    To the following lines:


    extern "C" { 

      int XPCALL MacroCmdChk(); 

    }


    int MacroCmdChk2 (char* cmd) {

      int result;

      __asm mov esi, cmd

      __asm call MacroCmdChk

      __asm xor eax,eax

      __asm adc eax,0

      __asm mov result, eax

      return result;

    }


    void SendRCV20( char* str) {

      char* cmdName = "RCV20";

      SetVar("RCVDATA", str);

      if (!MacroCmdChk2(cmdName)) {

       MessageBox(NULL, cmdName, "Message received from Core Rules II", MB_OK);

      }

    }


    void XPCALL About() {

      SendRCV20( "LINE 0,0;100,100"); 

    CmdEnd();

    }

    Monsen
  • jslaytonjslayton Moderator, ProFantasy Mapmaker

    I'm glad to hear that you got it working.

  • MonsenMonsen Administrator 🖼️ 51 images Cartographer

    Won't help you now that you got it working, but I should probably put this into a blog article for future users.

    Loopysue
  • That's a good idea, Remy, I was waiting for part 4 of the XP tutorial anyway ;-)

    BTW, during the installation of the VS template I got an error. (Visual Studio 17 Community 15.9.2).

    Probably you really have to use VS 19. I got the installation running under VS 17 with the following 2 changes:

    In extension.vsixmanifest two times: version="[15.0,)"

    In catalog.json: "Microsoft.VisualStudio.Component.CoreEditor": [15.0,17.0]"

  • MonsenMonsen Administrator 🖼️ 51 images Cartographer

    Thanks.

    I developed that template under VS19, which is why it probably requires it by default, but it doesn't really take advantage of any new features or anything.

    Technically, there is no reason at all to use VS19 for XP development, but it happened to be ready for release at about the same time as my first blog article, so I decided to use that, since that was the version people would find at the MS download site. I actually wrote the blog article while using the beta version, and released it on the same day VS19 was released.

    Loopysue
Sign In or Register to comment.