hexagon logo

Got Visual Studio and the Interop.PCDLRN.dll... Now what?

As I upgraded one CMM to Windows 7 64-bit, my small VBS helpers died in the process (still kickin' butt on XP though).
So, I have begun re-coding them in Visual Studio 2010 (I think). I have gotten so far in the coding where I need to connect to PC-DMIS and start interfacing with it. Now, I managed to find the DLL that is supposed to expose some interfaces and methods and I have successfully added it to my project.

Then what? How do I use the DLL to connect to PC-DMIS and expose the PartPrograms collection for instance?

Oh, I am using C# for this...

Any and all input, examples or suggestions are VERY welcome!

TIA!
Parents
  • This seems to work for me:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
    
            static Type PCDLRN_Application = null;
            static dynamic PCDApp = null;
            static dynamic PCDParts = null;
            static dynamic PCDPart = null;
    
            static void Main(string[] args)
            {
    
                try
                {
                    PCDLRN_Application = Type.GetTypeFromProgID("PCDLRN.Application");
                    PCDApp = System.Activator.CreateInstance(PCDLRN_Application);
                    PCDApp.WaitUntilReady(60);
                    System.Threading.Thread.Sleep(2000);
                    PCDApp.OperatorMode = false;
                    PCDApp.Visible = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.ReadLine();
                }
                Console.ReadLine();
            }
        }
    }


    To connect to an existing instance, you would need to use System.Runtime.InteropServices.Marshal.GetActiveObject instead of System.Activator.CreateInstance. I don't believe there is a simple way to do both from one call in C# (VB takes care of this in the background for you.)

    You may find it easier to reference to use VB for your resource management calls:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
    
            static Type PCDLRN_Application = null;
            static PCDLRN.Application PCDApp = null;
            static PCDLRN.PartPrograms PCDParts = null;
            static PCDLRN.PartProgram PCDPart = null;
    
            static void Main(string[] args)
            {
    
                try
                {
                    //PCDLRN_Application = Type.GetTypeFromProgID("PCDLRN.Application");
                    PCDApp = (PCDLRN.Application)Microsoft.VisualBasic.Interaction.CreateObject("PCDLRN.Application","");
                    PCDApp.WaitUntilReady(60);
                    System.Threading.Thread.Sleep(2000);
                    PCDApp.OperatorMode = false;
                    PCDApp.Visible = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.ReadLine();
                }
    
                Console.ReadLine();
            }
        }
    }
Reply
  • This seems to work for me:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
    
            static Type PCDLRN_Application = null;
            static dynamic PCDApp = null;
            static dynamic PCDParts = null;
            static dynamic PCDPart = null;
    
            static void Main(string[] args)
            {
    
                try
                {
                    PCDLRN_Application = Type.GetTypeFromProgID("PCDLRN.Application");
                    PCDApp = System.Activator.CreateInstance(PCDLRN_Application);
                    PCDApp.WaitUntilReady(60);
                    System.Threading.Thread.Sleep(2000);
                    PCDApp.OperatorMode = false;
                    PCDApp.Visible = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.ReadLine();
                }
                Console.ReadLine();
            }
        }
    }


    To connect to an existing instance, you would need to use System.Runtime.InteropServices.Marshal.GetActiveObject instead of System.Activator.CreateInstance. I don't believe there is a simple way to do both from one call in C# (VB takes care of this in the background for you.)

    You may find it easier to reference to use VB for your resource management calls:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
    
            static Type PCDLRN_Application = null;
            static PCDLRN.Application PCDApp = null;
            static PCDLRN.PartPrograms PCDParts = null;
            static PCDLRN.PartProgram PCDPart = null;
    
            static void Main(string[] args)
            {
    
                try
                {
                    //PCDLRN_Application = Type.GetTypeFromProgID("PCDLRN.Application");
                    PCDApp = (PCDLRN.Application)Microsoft.VisualBasic.Interaction.CreateObject("PCDLRN.Application","");
                    PCDApp.WaitUntilReady(60);
                    System.Threading.Thread.Sleep(2000);
                    PCDApp.OperatorMode = false;
                    PCDApp.Visible = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.ReadLine();
                }
    
                Console.ReadLine();
            }
        }
    }
Children
No Data