none
Marshalling RRS feed

  • Question

  • Hello

    I need to marshal a structure from C to C# which contains CDaoDatabase  as member. Is it possible?

    Thanks

    Thursday, July 23, 2009 11:33 PM

Answers

  • The problem is that it's really a class, and it's really going to be the behavior from that you need.  You'll probably just want a reference class that holds a pointer to your CDaoDatabase class, and that provides methods that call into the member variable - a very thin wrapper.

    For some sample code on how to approach this, I'd read this article .  The relevant section is titled: Wrapping Native Code to Publish within .NET
    Reed Copsey, Jr. - http://reedcopsey.com
    • Marked as answer by eryang Thursday, July 30, 2009 10:07 AM
    Thursday, July 23, 2009 11:47 PM
    Moderator

All replies

  • You would be able to marshall a pointer to the CDaoDatabase to an IntPtr, but I wouldn't recommend it in general.

    I'd recommend reworking this and making a C++/CLI wrapper around the API you're trying to expose that includes CDaoDatabase, and expose that API in a much more familiar manner, using .NET framework interfaces.
    Reed Copsey, Jr. - http://reedcopsey.com
    Thursday, July 23, 2009 11:37 PM
    Moderator
  • Thanks Reed,

    I have other unmanaged function and structures that I was able to use the Interop services and marshalling from C# to call them and this is struct is the problematic one.

    Can I make the managed C++ wrapper only for that specefic struct?

    Can you, please,  point me any example for that?

    Thanks

    Thursday, July 23, 2009 11:44 PM
  • The problem is that it's really a class, and it's really going to be the behavior from that you need.  You'll probably just want a reference class that holds a pointer to your CDaoDatabase class, and that provides methods that call into the member variable - a very thin wrapper.

    For some sample code on how to approach this, I'd read this article .  The relevant section is titled: Wrapping Native Code to Publish within .NET
    Reed Copsey, Jr. - http://reedcopsey.com
    • Marked as answer by eryang Thursday, July 30, 2009 10:07 AM
    Thursday, July 23, 2009 11:47 PM
    Moderator