locked
MSRS Service talking to unmanaged C++ dll RRS feed

  • Question

  • I have an unmanaged C++ DLL socket library that I would like to use from an MSRS service. Is there  good doc on how to call  an unmanaged C++  dll from  C#. I've found a lot of stuff out there but nothing that shows how to instantiate a class and then call methods on the handle. I would also like to do this with the MSRS service and socket library running on Win CE.
    Monday, October 22, 2007 6:47 PM

Answers

  • You can call native C++ dlls using PInvoke from C#, it's a standart .net approach. You can read more about it for example here: http://msdn2.microsoft.com/en-us/library/aa719104(vs.71).aspx. This is the prefered way of doing interop with native code for MSRS, but there are situations where it might not be the right thing to do.

     

    You must know however, that PInvoke does not allow you to call into C++ OOP code, meaning you can not create an instance of a native C++ class and call methods on it from C#. To do that you will have to iether wrap your C++ APIs into C style function call APIs, or use C++\CLI for you DSS service.

     

    If you program your DSS services directly in C++\CLI you will also have full control over the native to managed marshalling. If you choose to go the C++ DSS service route, I've prevoiusly posted some additional C++ samples to Channel 9 downloads, here are the links to the forum threads for them:

     

    Basic C++ Robotics Tutorials:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1935994&SiteID=1

     

    More Advanced C++\CLI samples: integration with the DDK:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2091502&SiteID=1

     

    The goal was to show how to do full DSS services as well as interop between managed and native code using C++ \CLI language. In many scenarios however, you might prefer to use PInvoke from C# to call into external C++ native DLLs.

     

    Pavel
    Wednesday, October 24, 2007 12:26 AM

All replies

  • You can call native C++ dlls using PInvoke from C#, it's a standart .net approach. You can read more about it for example here: http://msdn2.microsoft.com/en-us/library/aa719104(vs.71).aspx. This is the prefered way of doing interop with native code for MSRS, but there are situations where it might not be the right thing to do.

     

    You must know however, that PInvoke does not allow you to call into C++ OOP code, meaning you can not create an instance of a native C++ class and call methods on it from C#. To do that you will have to iether wrap your C++ APIs into C style function call APIs, or use C++\CLI for you DSS service.

     

    If you program your DSS services directly in C++\CLI you will also have full control over the native to managed marshalling. If you choose to go the C++ DSS service route, I've prevoiusly posted some additional C++ samples to Channel 9 downloads, here are the links to the forum threads for them:

     

    Basic C++ Robotics Tutorials:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1935994&SiteID=1

     

    More Advanced C++\CLI samples: integration with the DDK:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2091502&SiteID=1

     

    The goal was to show how to do full DSS services as well as interop between managed and native code using C++ \CLI language. In many scenarios however, you might prefer to use PInvoke from C# to call into external C++ native DLLs.

     

    Pavel
    Wednesday, October 24, 2007 12:26 AM
  • The Links are not working.
    **********************************************
    Christian Böpple
    Saturday, October 30, 2010 1:23 PM
  • The C++ samples were moved to CodePlex when RDS 2008 R3 was released. You can find them here:

    http://mrdssamples.codeplex.com

    Trevor

     

    Sunday, October 31, 2010 6:39 AM