MapInfo Pro Developers User Group

Expand all | Collapse all

Calling a procedure in another running MapBasic application

Jump to Best Answer
  • 1.  Calling a procedure in another running MapBasic application

    Posted 22 days ago

    I was asked how to call a procedure in a running MapBasic application from another MapBasic application.

    This can be done using the CallMBXSub method from the IMapInfoPro.def.

    Using the CallMBXSub method

    In IMapInfoPro.def you can find these two methods:

    Declare Method MapBasicApplication Class "MapInfo.Types.IMapInfoPro" Lib "MapInfo.Types, Version=12.5.0.0, Culture=neutral, PublicKeyToken=1c8d81d2ee78b75d" alias GetMapBasicApplication (ByVal IMIProInstance As This, ByVal applicationName As String) As This

    Declare Method CallMBXSub Class "MapInfo.Types.IMapBasicApplication" Lib "MapInfo.Types, Version=12.5.0.0, Culture=neutral, PublicKeyToken=1c8d81d2ee78b75d" alias CallMapBasicSubroutine (ByVal IMBXInstance As This, ByVal methodName As String, parameters() As String)

    The first one can give you a reference to a running MapBasic application using the name of the application.

    The second one lets you call a sub procedure in a running MapBasic application

    Here's how you can use it:

    Include "MapBasic.def"
    Include "IMapInfoPro.def"

    Declare Sub Main
    Sub Main
    Dim theMapInfoApplication As This
    Dim theOtherMapBasicApplication As This
    Dim arrParams() As String
       'Get the MapInfo Pro instance

       theMapInfoApplication = SystemInfo(SYS_INFO_IMAPINFOAPPLICATION)
       'Get the instance of the other MapBasic application
       theOtherMapBasicApplication = MapBasicApplication(theMapInfoApplication, "HexagonTool.mbx")


       'Call the procedure in the other MapBasic application
       Call CallMBXSub(theOtherMapBasicApplication, "MENUHexagons", arrParams)
    End Sub

    In my example, my running application HexagonTool.mbx has a procedure called MENUHexagons that doesn't take any parameters. If your procedure does take parameters, you will have to add these to the array arrParam in the order the procedure requires them.



    ------------------------------
    Peter Horsbøll Møller
    Pitney Bowes
    ------------------------------


  • 2.  RE: Calling a procedure in another running MapBasic application
    Best Answer

    Posted 17 days ago
    Hi Peter,
    Isn't that the same as using the Exec command, or am I missing something?
    You posted a message on using the Exec command sometime ago, which is what we tend to use.

       if sParam <> "" then
        nret = Exec(sMBX,sProc,sParam)
       else
        nret = Exec(sMBX,sProc)
       end if

    David


    ------------------------------
    David Wilson
    Buchanan Computing
    London, UK
    ------------------------------



  • 3.  RE: Calling a procedure in another running MapBasic application

    Posted 17 days ago
    Thanks for reminding me of this function, David.
    I almost forgot about since we introduced the methods for registering MapBasic functions in MapInfo Pro.

    Your solution is a lot easier than mine.

    ------------------------------
    Peter Horsbøll Møller
    Pitney Bowes
    ------------------------------