sending pointer from C++ to C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arjun404346
    New Member
    • Jul 2010
    • 3

    sending pointer from C++ to C#

    Hello all,
    I have to send a pointer from C++ to C#. How can I do this?
    Error message I am getting on the C# program is
    "Pointers and fixed size buffers may only be used in an unsafe context"
    Please help.
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    When using pointers in C#, you need to wrap the code in an unsafe code block.

    Code:
    unsafe
    {
      // your pointer operations here
    }

    Comment

    • arjun404346
      New Member
      • Jul 2010
      • 3

      #3
      thnx,
      now its showing error
      "Unsafe code requires the 'unsafe' command line option to be specified
      :( :(

      Comment

      • GaryTexmo
        Recognized Expert Top Contributor
        • Jul 2009
        • 1501

        #4
        In the Solution Explorer, find your project (the one that contains the unsafe code). Right-click and select properties. In the left-hand pane, select the Build tab.

        In the first category, General, there should be a checkbox that says "Allow unsafe code".

        Check this and save the properties.

        Comment

        • arjun404346
          New Member
          • Jul 2010
          • 3

          #5
          Actually I am working on unity3d and there is no setting option for compiling. I have to send a pointer from a C++ program (which is being compiled on Visual C++) to C# program (which is being compiled by unity3d compiler).

          I have to change IplImage (contained in openCv library for C) to Texture2D image (used by unity3d) and for that I have to tell unity3d where this IplImage is stored in the memory. And so I need to send a pointer

          Comment

          • GaryTexmo
            Recognized Expert Top Contributor
            • Jul 2009
            • 1501

            #6
            Google around for it. It's a command line switch on the compiler itself. If you're not using Visual Studio, you'll have to figure out how to enable that as a compile option on the tool you are using.

            I'm think it might be something as simple as adding /unsafe to the command line for it, but I'm not sure... which is why you should look it up :)

            Comment

            Working...