Click here to Skip to main content
12,395,871 members (65,186 online)

Managed C++/CLI

 
AnswerRe: Structures with using bit fields Pin
Richard MacCutchan29-Jan-13 3:38
mvpRichard MacCutchan29-Jan-13 3:38 
GeneralRe: Structures with using bit fields Pin
Amrit Agr17-Feb-13 22:06
memberAmrit Agr17-Feb-13 22:06 
Questionsopen() function in filehandling - "C" Pin
Amrit Agr28-Jan-13 0:56
memberAmrit Agr28-Jan-13 0:56 
AnswerRe: sopen() function in filehandling - "C" Pin
John Schroedl28-Jan-13 3:37
memberJohn Schroedl28-Jan-13 3:37 
AnswerRe: sopen() function in filehandling - "C" Pin
ramrooney27-Mar-13 7:36
memberramrooney27-Mar-13 7:36 
QuestionHow to call a static libray in a dll? Pin
LongFangFang21-Jan-13 19:38
memberLongFangFang21-Jan-13 19:38 
AnswerRe: How to call a static libray in a dll? Pin
Richard MacCutchan21-Jan-13 22:32
mvpRichard MacCutchan21-Jan-13 22:32 
Questionfrom unmanaged c++ to managed: passing int& parameter Pin
acastrucc19-Dec-12 4:30
memberacastrucc19-Dec-12 4: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 Pin
tcnm12-Dec-12 9:18
membertcnm12-Dec-12 9:18 
QuestionRe: Compilation Problem Pin
Richard MacCutchan12-Dec-12 22:56
mvpRichard MacCutchan12-Dec-12 22:56 
Answer-Re: Compilation Problem Pin
tcnm14-Dec-12 6:42
membertcnm14-Dec-12 6:42 
GeneralRe: -Re: Compilation Problem Pin
Richard MacCutchan14-Dec-12 21:43
mvpRichard MacCutchan14-Dec-12 21:43 
QuestionWhy c is so important? Pin
riceshoots10-Dec-12 4:47
memberriceshoots10-Dec-12 4:47 
AnswerRe: Why c is so important? Pin
Richard MacCutchan10-Dec-12 5:52
mvpRichard MacCutchan10-Dec-12 5:52 
QuestionPlease vote for C++/CLI debug visualizer support Pin
John Schroedl7-Dec-12 4:25
memberJohn Schroedl7-Dec-12 4:25 
QuestionHow to use NTGraph3D Activex Control in Visual Studio 2010. Pin
DhrumilS23-Nov-12 0:47
memberDhrumilS23-Nov-12 0:47 
AnswerRe: How to use NTGraph3D Activex Control in Visual Studio 2010. Pin
Richard MacCutchan23-Nov-12 1:44
mvpRichard MacCutchan23-Nov-12 1:44 
Question'J' Character printed on empty fields on dialogs Pin
cnuis2kool18-Nov-12 22:29
membercnuis2kool18-Nov-12 22:29 
Questionhow to get programettically a registered DLL's Version information? Pin
litu kumar7-Nov-12 21:32
memberlitu kumar7-Nov-12 21:32 
AnswerRe: how to get programettically a registered DLL's Version information? Pin
Richard MacCutchan7-Nov-12 21:43
mvpRichard MacCutchan7-Nov-12 21:43 
GeneralRe: how to get programettically a registered DLL's Version information? Pin
litu kumar7-Nov-12 21:52
memberlitu kumar7-Nov-12 21:52 
GeneralRe: how to get programettically a registered DLL's Version information? Pin
Richard MacCutchan8-Nov-12 0:04
mvpRichard MacCutchan8-Nov-12 0:04 
GeneralRe: how to get programettically a registered DLL's Version information? Pin
H.Brydon1-Jan-13 9:46
memberH.Brydon1-Jan-13 9:46 
GeneralRe: how to get programettically a registered DLL's Version information? Pin
Richard MacCutchan1-Jan-13 22:14
mvpRichard MacCutchan1-Jan-13 22:14 
GeneralRe: how to get programettically a registered DLL's Version information? Pin
H.Brydon2-Jan-13 5:03
memberH.Brydon2-Jan-13 5:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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
Web01 | 2.8.160721.1 | Last Updated 19 Jul 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid