Passing reference values to C++ functions

I am trying to use the C++ funtions in C# through DLL reference.
I need to pass values by reference to these functions.
How is this possible in C#

Thanks and Regards
Madhu



Answer this question

Passing reference values to C++ functions

  • naeem khan

    Use the 'ref' keyword.

    e.g., if you're calling "SomeMethod";

    SomeMethod(ref SomeArg);

    David Anton
    www.tangiblesoftwaresolutions.com
    Instant C#: VB to C# Converter
    Instant VB: C# to VB Converter
    Instant C++: C# to C++ and VB to C++ Converter
    Instant J#: VB to J# Converter
    Clear VB: Cleans up VB code
    Clear C#: Cleans up C# code



  • Piepens

    Check out the samples included in the sdk, there are some good ones demonstrating various pinvoke declarations.

    Also check out this page: http://msdn.microsoft.com/netframework/programming/interop/default.aspx

    The first few links include some great resources for dealing with platform invoke (calling C++ methods from managed code) and should be able to help you out here.


  • Vassil Kovatchev

    Hi David,

    I tried using ref but then it returns an error even then.

    It tells unable to convert (data type) to *(data type)

    In that case i have to declare it as pointers. But if i do so then it becomes unsafe...

    how can this be overcome

    Thanks in advance

    MadhuSri


  • Passing reference values to C++ functions