MapInfo Pro Developers User Group

 View Only
  • 1.  Calling Method in a DLL fails at MapInfo runtime, while running an app.

    Posted 08-10-2022 04:29
    I wrote a very simple code in VB.NET to send just a key to active window, conpiled into DLL. Also wrote a MapBasic app that recalls that DLL but at runtime MapInfo fails.

    My VB.NET code:

    Imports Microsoft.VisualBasic.Devices
    Namespace MyApp1
        Public Class SENDKEY2MAPINFO
            Public Shared Function SENDKEYX(s_key As String) As String
                My.Computer.Keyboard.SendKeys(s_key, True)
                Return 0
            End Function
        End Class
    End Namespace
    It compliles right into "SendKey2Mapinfo.dll"
    My MB code:
    Declare Method SENDKEYX Class "MyApp1.SENDKEY2MAPINFO" Lib "SendKey2MapInfo.dll" (ByVal s_key as String) As String
    ...   ...   ...
    Dim retval, s_key as String
    s_key="{C}"
    retval = SENDKEYX(s_key)
    At runtime it crashes with the message : "(appname.mb:line) Could not find class "MyApp1.SENDKEY2MAPINFO". TypeLoadException, Could not load type 'MyApp1.SENDKEY2MAPINFO' from assembly 'SendKey2MapInfo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. "
    The same failing result if the VB.NET code is 
     Imports Microsoft.VisualBasic.Devices
    Namespace MyApp1
        Public Class SENDKEY2MAPINFO
            Public Shared Function SENDKEYX(s_key As String)
                My.Computer.Keyboard.SendKeys(s_key, True)
                Return 0
            End Function
        End Class
    End Namespace
    And MB code is:
    Declare Method SENDKEYX Class "MyApp1.SENDKEY2MAPINFO" Lib "SendKey2MapInfo.dll" (ByVal s_key as String)
    ...   ...   ...
    ...
    Call SENDKEYX(s_key)
    Without parameters, the result is the same fail.
    I'm editing VB.NEt with VisualStudio, is tehre any compilation option to look at?

    May anyone find where the problem is?
    Thank you in advance.
    SGR


    ------------------------------
    Sergi Gamiz-Ribelles
    Knowledge Community Shared Account
    ------------------------------


  • 2.  RE: Calling Method in a DLL fails at MapInfo runtime, while running an app.

    Employee
    Posted 08-12-2022 10:31
    Hi Sergi,

    In comparing your code to HelloWorld.mb I noticed that you declared a shared function.
    This does not match with your mapbasic declare method statement as there is no return type on it.
    Also 'call' is used for calling subroutines not functions.

    I think since you do not need the return type the simplest fix is to change your mb to a sub like this:
    Public Shared Method SENDKEYX(s_key As String)
    Then your declare and call statement should work.

    Lastly I am not sure if SendKeys will work or not since each mbx that uses .net creates a new app domain for it.
    Try it out. Maybe add a messagebox to prove that your .net code is getting called.
    System.Windows.Forms.MessageBox.Show("Hello, " + s)

    -Bob

    ------------------------------
    Bob Fortin
    Software Architect and Distinguished Engineer
    MapInfo Pro Development Team
    ------------------------------



  • 3.  RE: Calling Method in a DLL fails at MapInfo runtime, while running an app.

    Posted 08-16-2022 10:37
    Hi Bob, Thank you. I solved the problem modifying the declare statement, and now my MB code executes correctly the DLLs.
    But as you said, SendKeys doesn't work properly with MapInfo: Sendkeys certainly sends keys or text as spected but MapInfo is not able to react to those keys.

    SGR

    ------------------------------
    Sergi Gamiz-Ribelles
    Knowledge Community Shared Account
    ------------------------------