Passing Data From C# To Managed C++ Lib
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Passing Data From C# To Managed C++ Lib

  1. #1
    Join Date
    Aug 2010
    Posts
    2

    Question Passing Data From C# To Managed C++ Lib

    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:
    #pragma once
    
    #include <comdef.h>
    #include <comutil.h>
    
    using namespace System;
    using namespace System::Runtime::InteropServices;
    
    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.

  2. #2
    Join Date
    Aug 2010
    Posts
    2

    Re: Passing Data From C# To Managed C++ Lib

    mmm sorry about the poor grammar I was typing a bit fast here and I don't see an edit button anywhere

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center