How to Use Structures or Arrays in Methods that are to be COM Visible

Category: c# language


Al Willis on Thu, 09 Jul 2009 23:39:21

I have been able to successfully call my C# DLL from Delphi when using simple data types like double, int or string.  How do I pass complex objects like structures or arrays of structures?  I've made the DLL to have a COM wrapper.

The following code works:

namespace DwgLib
    public interface DwgLib_Interface
        void GetDrawingData(string inputFileName, string outputFileName);
        void InitializeDrawingServices();
        void DisposeDrawingServices();
        void WriteDrawingData(string modelDwgFullPath, string loopDwgFullPath, string dwgCommandsFileName, string resultsFileName);

    // Events interface  
    public interface DwgLib_Events

    public class Dwg : DwgLib_Interface
        public void InitializeDrawingServices()

        public void DisposeDrawingServices()

        public void GetDrawingData(string inputFileName, string outputFileName) 

        public void WriteDrawingData(string modelDwgFullPath, string loopDwgFullPath, string dwgCommandsFileName, string resultsFileName)

I would like to pass an array of the following structure as a parameter in one of the COM visible methods.

        struct dwgInsertRec
            string blockName;
            string insertName;
            string insertHandle;
            string objectID;
            string layerName;
            double x;
            double y;
            double z;
            int qtyAttr;
            int qtyConstAttr;
            int qtyRows;
            int qtyColumns;
            string elementID;

A variable declaration would look like this:  dwgInsertRec[] someArrayName;

I don't know where to put the struct definition to make this work.




Martijn Bos on Tue, 23 Oct 2012 08:18:34

I'm not sure but can you not just make a public interface DwgInsertRec(dwgInsertRec[]){} that expects the struct as a variable?

Karmjit Singh on Tue, 23 Oct 2012 13:23:48

see if this helps