1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Passing Data From C# To Managed C++ Lib

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

  1. littlespy

    littlespy New Member

    Aug 31, 2010
    Likes Received:
    Trophy Points:
    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

    namespace ArcProxy {
            public ref class ArcProxy
                            ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
                    void PointOperations(void *ipPointFeatures, long numPoints)
                            IFeatureCursor *cur;
                            VARIANT 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:
                    ArcProxy.ArcProxy proxy = new ArcProxy.ArcProxy();
                        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