none
Using an unmanaged C++ library with a .NET API RRS feed

  • Question

  • I have a project where I must make use of an API to read file of a proprietary filetype. It is closed source, just a bunch of DLLs that can be added as a reference in my project (currently I am using C# but I would be happy to move to VC++ if it would be easier). However, I also wish to make use of a C++ library, OpenMS (http://open-ms.sourceforge.net/) in order to manage and analyse the data I obtain. I have read a bit about P/Invoke and creating a wrapper but I am not sure how I should go about this and what the best way would be, especially as most examples I have seen are very simple and this library has many complex data types and is simply very large and complicated. Is it possible to automate the process of creating a wrapper as the library is very large?

    I have read about "It Just Works" and I was wondering if this functionality might be appropriate, or at least faster, perhaps giving me a reason to migrate to C++.

    Monday, February 6, 2012 6:44 PM

Answers

  • The only wrapper generator I know is for COM servers for C++.  This of course doesn't mean that OpenMS cannot be used in .Net (I actually don't know as I have never tried it or even examined this library).  Your best shot would be to continue reading about P/Invoke and conclude by yourself if it is a viable option.  Meaning:  You'll have to read more than just "a bit" about P/Invoke.
    Jose R. MCP
    • Marked as answer by Paul Zhou Thursday, February 16, 2012 8:18 AM
    Monday, February 6, 2012 8:20 PM

All replies

  • The only wrapper generator I know is for COM servers for C++.  This of course doesn't mean that OpenMS cannot be used in .Net (I actually don't know as I have never tried it or even examined this library).  Your best shot would be to continue reading about P/Invoke and conclude by yourself if it is a viable option.  Meaning:  You'll have to read more than just "a bit" about P/Invoke.
    Jose R. MCP
    • Marked as answer by Paul Zhou Thursday, February 16, 2012 8:18 AM
    Monday, February 6, 2012 8:20 PM
  • Thanks for the advice.  I have been reading a fair bit but it has been confusing, so I will keep reading, hopefully I can find something soon.  I have been able to compile a program that includes the c++ headers from OpenMS but not actually been able to use the methods using the C++ interop functionality.  I think I need to read more about how to marshall the objects.
    Tuesday, February 7, 2012 7:32 PM
  • A good arcticle from MS about Marshaling between managed and unmanaged code:

    http://msdn.microsoft.com/en-us/magazine/cc164193.aspx


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, February 16, 2012 8:20 AM