Pass CString and byte array from native C++ to managed C++

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Notre Poubelle

    #1

    Pass CString and byte array from native C++ to managed C++

    Hello,

    I have a scenario where my CPP project is not compiled with CLR support,
    but some of the CPP files have the /clr option set. In file1.cpp, the /clr
    switch is not set. In file2.cpp, the /clr switch is set. file2.h is the
    header for file2.cpp, and this header is included in file1.cpp. file2.h
    contains method signatures containing only native types, including some
    funtions which take a CString parameter or a const pointer to char, e.g.

    void MyFunc (const char* param);

    Methods in file1.cpp calls the functions declared in file2.h (and
    implemented in file2.cpp), including the two with a CString and const pointer
    to char parameters. My question is, should I be doing any marshalling of
    data at this point (presumably in file1.cpp) when moving from native to
    managed code? If so, what type of marshalling should I do and how?

    Thank you,
    Notre
  • David Lowndes

    #2
    Re: Pass CString and byte array from native C++ to managed C++

    >My question is, should I be doing any marshalling of
    >data at this point (presumably in file1.cpp) when moving from native to
    >managed code?
    No, it should just work seamlessly.

    Are you having a problem?

    Dave

    Comment

    • Notre Poubelle

      #3
      Re: Pass CString and byte array from native C++ to managed C++

      Hi David,

      No, I'm not seeing any problem. I just thought that when passing
      non-primitive values from native to managed code I would need to do some type
      of marshalling.

      The compiler does complain when trying to use native & managed types that
      don't match. However, the compiler doesn't catch the case where native code
      holds a reference to a managed object, which can be garbage collected if not
      pinned. I thought there might be something I need to do in the scenario I
      described earlier as well (but don't know what)...

      Notre

      Comment

      • David Lowndes

        #4
        Re: Pass CString and byte array from native C++ to managed C++

        >Hi David,
        >
        >No, I'm not seeing any problem.
        That's always reassuring :)
        >I just thought that when passing
        >non-primitive values from native to managed code I would need to do some type
        >of marshalling.
        I won't pretend to know what goes on since I've not yet needed to
        know, but one of the essential points of the C++ compiler was that it
        should just work (the old IJW "It Just Works" TLA) with /clr.

        Dave

        Comment

        • =?Utf-8?B?UC5Hb3BhbGFLcmlzaG5h?=

          #5
          RE: Pass CString and byte array from native C++ to managed C++

          Hello,

          Please check if the post at:
          http://blogs.msdn.com/gpalem/archive...-c-to-net.aspx
          is useful.

          P.Gopalakrishna .
          Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!


          "Notre Poubelle" wrote:
          Hello,
          >
          I have a scenario where my CPP project is not compiled with CLR support,
          but some of the CPP files have the /clr option set. In file1.cpp, the /clr
          switch is not set. In file2.cpp, the /clr switch is set. file2.h is the
          header for file2.cpp, and this header is included in file1.cpp. file2.h
          contains method signatures containing only native types, including some
          funtions which take a CString parameter or a const pointer to char, e.g.
          >
          void MyFunc (const char* param);
          >
          Methods in file1.cpp calls the functions declared in file2.h (and
          implemented in file2.cpp), including the two with a CString and const pointer
          to char parameters. My question is, should I be doing any marshalling of
          data at this point (presumably in file1.cpp) when moving from native to
          managed code? If so, what type of marshalling should I do and how?
          >
          Thank you,
          Notre

          Comment

          Working...