I am trying to work out how to pass a pointer from my C# interface application to the C++ back-end functionality DLL.

I tried searching Google but can't work out what I'm doing wrong.. I'm used to using * for pointers and just changing the value in the pointer through direct assignment but in C# to C++ interactions I'm using ^ and don't know how to change the variable declared in C# so I can pass values to the C# interface.

in C++ i have

int MediaMogul::readlist(String^ name)
{
    name = "changed value";
    return 0;
}

and in C# I have

private void AddExistingMedia_DoWork(object sender, DoWorkEventArgs e)
{
    MediaMogul item = new MediaMogul();
    String name = "string to be replaced";

    MessageBox.Show(name, "String");

    item.readlist(name)

    MessageBox.Show(name, "String");
}

I'd be grateful for any information regarding .NET C# -> C++ pointers

You can pass a ref parameter in C++/CLI using the '%' operator, it corresponds to standard C++'s reference operator(&):

int MediaMogul::readlist(String^% name)
{
    name = "changed value";
    return 0;
}
commented: Thankyou, I also worked out from that how to pass to the C++ DLL using item.readlist(ref name); in C# +0
commented: Deep knowledge! +14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.