Passing Data From C# To Managed C++ Lib

Discussion in 'C#' started by littlespy, Aug 31, 2010.

  1. littlespy

    littlespy New Member

    Joined:
    Aug 31, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi,
    We are building a GIS application that must make many repetitive calls in a small amount of time. (IE processing thousands of points in a few seconds). Because of the way the ESRI ArcObjects framework we are using interfaced with COM components through the interop layer we have decided to move the heavy parts of our application out our C# program and into managed c++.


    Which leads me to the problem that I've been tackling all day. I've built a .NET managed class in C++ and an importing it into my C# application by adding a reference to the DLL. That all works fine, but as for passing a Class object from the C# program to the DLL I have been having a lot of trouble. Here is some code to help clarify:

    This is the C++ Class, pretty simple

    Code:
    namespace ArcProxy {
    
            public ref class ArcProxy
            {
            public:
                    ArcProxy()
                    {
                            ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
                            //ESRI_SET_VERSION(esriArcGISEngine);
                    }
    
                    ~ArcProxy()
                    {
                            ::CoUninitialize();
                    }
    
                    void PointOperations(void *ipPointFeatures, long numPoints)
                    {
                            IFeatureCursor *cur;
                            VARIANT v;
                            //v.
    
                            IFeatureClass * fc = (IFeatureClass *)ipPointFeatures;
                            fc->GetFeatures(v, true, &cur);
                            
                            //return ipPointFeatures;
                    }
    
                    int test() { return 2;}
            };
    }
    
    I am trying to call it in my C# doing something like this:
    Code:
                    ArcProxy.ArcProxy proxy = new ArcProxy.ArcProxy();
    
                    unsafe
                    {
                        IntPtr refPtr = new IntPtr();
                        Marshal.StructureToPtr(sourceFeatureClass, refPtr, true);
    
                        proxy.PointOperations(refPtr.ToPointer(), 100000);
                    }
    
    I am a bit confused as to how I can pass a managed object from C# to managed c++. sourceFeatureClass is just an object of type IFeatureClass (if anyone is familar with arcobjects). If I can pass the data in as a void * to my c++ dll then I can simply cast the void * to a IFeatureClass * in c++ and be happily on my way.

    If anyone could provide any insight into this problem I would be very grateful.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice