MapInfo Pro

 View Only
  • 1.  Problem Statement: Issues with Creating a MapInfo Instance in .Net Application (MapInfo 2023)

    Posted 19 days ago

    I am currently working on a MapInfo-based application using .NET and Visual Studio 2017. The application is developed with C#.NET Framework 4.7.2 on a Windows 10 system. The goal is to interact with MapInfo Professional to perform specific tasks. However, I am encountering challenges while creating the MapInfo instance in the 2023 version.

    The same code or approach worked fine in earlier versions, but in this version, the MapInfo instance is not initializing as expected.

    Here are the details of the problem:

    • Environment:

      • MapInfo Professional 2023
      • Visual Studio 2017
      • C#.NET Framework 4.7.2
      • Windows 10
    • Issue: When attempting to create the MapInfo instance, the initialization process fails. The instance is not created, and the application cannot proceed further. No specific error messages are displayed.

    • Expected Outcome: The MapInfo instance should initialize correctly, enabling interaction as intended.

    • Troubleshooting Attempts: I have tried using various DLLs provided with MapInfo Professional 2023 to address potential compatibility or functionality issues, but the problem persists.

    Has anyone else experienced similar issues with the 2023 version? Are there any changes in the DLLs, or initialization process specific to this version? Could the issue be related to the .NET framework version or Visual Studio compatibility? Any guidance or suggestions would be greatly appreciated.



    ------------------------------
    Jayant Grover
    Knowledge Community Shared Account
    Burlington MA
    ------------------------------


  • 2.  RE: Problem Statement: Issues with Creating a MapInfo Instance in .Net Application (MapInfo 2023)

    Employee
    Posted 18 days ago

    Hey Jayant

    This is a copy of the reply I sent to the MapInfo-L

    In the IntegratedMappingWpf example that comes with MapBasic v2023, I can see the MapInfo Pro is initiated using this statement:

          // Initialize the IMapInfoApplication interface.

          Application = MapInfoCore.Initialize(this, this);

          if (Application == null)

          {

                return;

          }

    We do supply four samples with MapBasic.

    Can you check them out and see if this approach works for you?

    I can't tell from your screenshot if this is calling a constructor of your own.

    _MIApp = new MapInfoApplication()



    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------



  • 3.  RE: Problem Statement: Issues with Creating a MapInfo Instance in .Net Application (MapInfo 2023)
    Best Answer

    Posted 18 days ago

    Hi Peter 

    The samples provided by MapInfo demonstrate creating instances for integrated MapInfo . Alternatively, We have initialized MapInfo using its registry ID which is compatible for the MapInfo 16.0 and MapInfo 2024 

    Please find the attached code for reference.

    using System;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;

    namespace MapInfo_Temp
    {
        public partial class Form1 : Form
        {
            private dynamic _MapInfoApp;

            public Form1()
            {
                InitializeComponent();
            }

            private void Form1_Load(object sender, EventArgs e)
            {
                try
                {
                    _MapInfoApp = Activator.CreateInstance(Type.GetTypeFromProgID("MapInfo.Application.x64"));
                    System.Threading.Thread.Sleep(10);
                    _MapInfoApp.Do("Set ProgressBars OFF");
                    _MapInfoApp.Visible = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Unable To Initialize MapInfo Instance ({ex.ToString()})");
                    return;
                }
            }

            private void button1_Click(object sender, EventArgs e)
            {
                _MapInfoApp.Do(@"Open Table "Path of Your File" as tableName");
                _MapInfoApp.Do("Select * from tableName");
                _MapInfoApp.Do("Select count(*) from selection");
                int count = int.Parse(_MapInfoApp.Eval("Selection.count"));
                MessageBox.Show($"Count = {count}");
                MessageBox.Show("print(\"Hello\")");
                MessageBox.Show("Process Completed MapInfo Initialize Successfully.");
            }
        }
    }

    Thanks for your Support 
    Regards 
    Jayant Grover 


    ------------------------------
    Jayant Grover
    Knowledge Community Shared Account
    Burlington MA
    ------------------------------