Click here to Skip to main content
11,410,750 members (63,606 online)

Managed C++/CLI

 
AnswerRe: Structures with using bit fields PinmvpRichard MacCutchan29-Jan-13 4:38 
GeneralRe: Structures with using bit fields PinmemberAmrit Agr17-Feb-13 23:06 
Questionsopen() function in filehandling - "C" PinmemberAmrit Agr28-Jan-13 1:56 
AnswerRe: sopen() function in filehandling - "C" PinmemberJohn Schroedl28-Jan-13 4:37 
AnswerRe: sopen() function in filehandling - "C" Pinmemberramrooney27-Mar-13 8:36 
QuestionHow to call a static libray in a dll? PinmemberLongFangFang21-Jan-13 20:38 
AnswerRe: How to call a static libray in a dll? PinmvpRichard MacCutchan21-Jan-13 23:32 
Questionfrom unmanaged c++ to managed: passing int& parameter Pinmemberacastrucc19-Dec-12 5:30 
I have a third party unmanaged c++ library.
I created a managed c++ wrapper for it since I need to call it from c# code. Problem is one of native c++ functions passes an int by reference. I do not know how to route this through the managed wrapper to the c# code. For example

class A //unmnaged SDK class
{
public:
void Foo(int& i);
}

//managed c++ wrapper
public ref class A_Wrapper
{
public:
A_Wrapper() {_unmanaged = new A();};
~A_Wrapper() {delete unmanaged; };
void Foo(int& i) { _unmanaged->Foo(i)};
private:
A * _unmanaged;
}

In my c# (yes #) code I try to call A_Wrapper::Foo() but I get compile errors

c# code:
public static void Main()
{
A_Wrapper aw = new A_Wrapper();
int id = 0;
aw.Foo(&id);
}
error CS0214: Pointers and fixed size buffers may only be used in an unsafe context

I don't really want to wrap it in an unsafe {} block. How do I route the pass by reference from c++ to c# properly?


Update: Answered. (I figured it out) I had to change the wrapper class to use tracking references, i.e.

//managed c++ wrapper
public ref class A_Wrapper
{
public:
A_Wrapper() {_unmanaged = new A();};
~A_Wrapper() {delete unmanaged; };
void Foo(int% i)
{
int ret=0;
_unmanaged->Foo(ret);
i = ret;
};
private:
A * _unmanaged;
}

c# code:
public static void Main()
{
A_Wrapper aw = new A_Wrapper();
int id = 0;
aw.Foo(ref id);
}
QuestionCompilation Problem [modified] Pinmembertcnm12-Dec-12 10:18 
QuestionRe: Compilation Problem PinmvpRichard MacCutchan12-Dec-12 23:56 
Answer-Re: Compilation Problem [modified] Pinmembertcnm14-Dec-12 7:42 
GeneralRe: -Re: Compilation Problem PinmvpRichard MacCutchan14-Dec-12 22:43 
QuestionWhy c is so important? Pinmemberriceshoots10-Dec-12 5:47 
AnswerRe: Why c is so important? PinmvpRichard MacCutchan10-Dec-12 6:52 
QuestionPlease vote for C++/CLI debug visualizer support PinmemberJohn Schroedl7-Dec-12 5:25 
QuestionHow to use NTGraph3D Activex Control in Visual Studio 2010. PinmemberDhrumilS23-Nov-12 1:47 
AnswerRe: How to use NTGraph3D Activex Control in Visual Studio 2010. PinmvpRichard MacCutchan23-Nov-12 2:44 
Question'J' Character printed on empty fields on dialogs Pinmembercnuis2kool18-Nov-12 23:29 
Questionhow to get programettically a registered DLL's Version information? Pinmemberlitu kumar7-Nov-12 22:32 
AnswerRe: how to get programettically a registered DLL's Version information? PinmvpRichard MacCutchan7-Nov-12 22:43 
GeneralRe: how to get programettically a registered DLL's Version information? Pinmemberlitu kumar7-Nov-12 22:52 
GeneralRe: how to get programettically a registered DLL's Version information? PinmvpRichard MacCutchan8-Nov-12 1:04 
GeneralRe: how to get programettically a registered DLL's Version information? PinmemberH.Brydon1-Jan-13 10:46 
GeneralRe: how to get programettically a registered DLL's Version information? PinmvpRichard MacCutchan1-Jan-13 23:14 
GeneralRe: how to get programettically a registered DLL's Version information? PinmemberH.Brydon2-Jan-13 6:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.150414.5 | Last Updated 17 Apr 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid