Invoking C++ with pointer param from C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kenneth Porter

    Invoking C++ with pointer param from C#

    If a C++ method takes a pointer to an int for output (for example), how
    should C# pass the int into which it wants the result returned?

    (I'll post some test code shortly. I'm writing the question from memory
    after a meeting yesterday with a C# developer and need to recreate his two
    test projects. I've got some C++ that he needs to invoke. I'm new to C# but
    have dealt with low-level cross-language issues in other languages.)

    In C++, the method signature would look like one of:

    void fooptr(int* x);
    void fooref(int& x);

    How would C# invoke these?
  • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

    #2
    Re: Invoking C++ with pointer param from C#

    Kenneth Porter wrote:
    If a C++ method takes a pointer to an int for output (for example), how
    should C# pass the int into which it wants the result returned?
    In C++, the method signature would look like one of:
    >
    void fooptr(int* x);
    void fooref(int& x);
    >
    How would C# invoke these?
    [DllImport(@"C:\ ptr.dll")]
    private static extern void fooptr(ref int x);
    [DllImport(@"C:\ ptr.dll")]
    private static extern void fooref(ref int x);

    seems to work for me.

    Arne

    Comment

    Working...