none
Interop, optional solutions: Explicit marshalling or mixed mode? RRS feed

  • Question

  • Hi,

    I'm still having problem with an interop issue. I've posted about this issue before. To recap the issue: I have this native C library that does a bit of mathemetical calculations. The library exposes a quite complicated and messy function that looks like this:

    long TBAPI TbeAndring (short, 
          short,
          PTB_PU,
          PTB_ANDRING_INFO,
          PTB_PARAMS,
          PTB_PREMIE_NIVA_INFO,
          PTB_PREMIE,
          PTB_FORMAN_INFO,
          PTB_FORMAN,
          PTB_FUNK,
          PTB_PARAMS,
          PTB_PREMIE_NIVA_INFO,
          PTB_PREMIE,
          PTB_FORMAN_INFO,
          PTB_FORMAN,
          PTB_FUNK);
    
    

    The arguments are mainly composed by structs array of arbitrary length. The lengths are defined by the second short argument. Most of the arrays comes in pairs, for example you see that PTB_PARAMS occurs twice.  The second occurence can be an empty array.

    The solution I posted in the previous thread (same link as above) works most of the times. Now I've started to do some load tests and sometimes I get an AccessViolationException. I can see from the logs that the library is trying to read from an empty list! Only reading jibberish though.

    This p/invoke is really hard to understand and get a grip on, especially when I get problems when downgrading to .net 3.5 (also AccessViolationException).

    Should I try to marshal everything explicitly? If so, how the heck do I do that in this case? Another option would be Mixed Mode C++ wrapper. A wrapper that exposes CLR classes that the Vb.net solution can consume: Vb.net web service -> MM C++ wrapper -> Native C library. Could that be an option? If so, got any good examples? Never done Managed C++ before.

    Regards,
    Joakim.


    Joakim Rosendahl Consultant at Connecta AB, Sweden.
    Tuesday, January 4, 2011 11:55 AM

Answers

  • The VBCallNativeDllWrapper (of All-In-One Code Framework) sample demonstrates calling the functions and classes exported by a native C++ DLL module from VB.NET code through C++/CLI wrapper classes, hope it could be helpful:

     

      VBCallNativeDllWrapper (this .NET application)

              -->

          CppCLINativeDllWrapper (the C++/CLI wrapper)

                  -->

              CppDynamicLinkLibrary (a native C++ DLL module)


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by eryang Monday, January 17, 2011 1:20 PM
    Friday, January 7, 2011 3:07 AM