calling String ^ * from C#
-
I'm sure that this is a stupid question and that I am just missing some obvious but here it goes. I'm adding a remoting interface to an MFC service that I have. I've gotten it to compile and run with the CLI and now I'm porting the COM interface to a remoting interface. Then I hit a problem. I have some methods that return values as parameters..you know the old "BOOL *" and the ever popular "LPTSTR *"....anyway... in C++/CLI these get translated to Boolean * and String^ *. the problem is...HOW in the world do I call these from C#? I know it's a reference, but c++/cli doesn't support the keyword REF and c# doesn't like things like "&". I guess I could try to jump thru a lot of hoops and get it to work via unmanaged code, but this SEEMS like a simple syntax problem. sorry again to bother people with this, but for the life of me...I can't find the "right" keywords to get google to show me what I need. thanks, Gene
-
I'm sure that this is a stupid question and that I am just missing some obvious but here it goes. I'm adding a remoting interface to an MFC service that I have. I've gotten it to compile and run with the CLI and now I'm porting the COM interface to a remoting interface. Then I hit a problem. I have some methods that return values as parameters..you know the old "BOOL *" and the ever popular "LPTSTR *"....anyway... in C++/CLI these get translated to Boolean * and String^ *. the problem is...HOW in the world do I call these from C#? I know it's a reference, but c++/cli doesn't support the keyword REF and c# doesn't like things like "&". I guess I could try to jump thru a lot of hoops and get it to work via unmanaged code, but this SEEMS like a simple syntax problem. sorry again to bother people with this, but for the life of me...I can't find the "right" keywords to get google to show me what I need. thanks, Gene
-
Do you want to call String from c# to MFC or to c++/cli If you chose c++/cli, yust add a project to your solution, and add a reference.
What I'm trying to do is call the C++/cli from C#. The method I'm calling is trying to return an out parameter like String^ *. It would be a "ref" in c# and a & in normal C++. I did figure it out though. the magic symbol is %. it looks like % means ref in C++/CLI.
-
What I'm trying to do is call the C++/cli from C#. The method I'm calling is trying to return an out parameter like String^ *. It would be a "ref" in c# and a & in normal C++. I did figure it out though. the magic symbol is %. it looks like % means ref in C++/CLI.
Let's say you have a class in C#. And both project are under your solution. Go to c++/cli project setting, and add a reference by projects, and select a project c#. When in c++/cli: using namespace projectCSharNamespace; projectCSharpClass ^cl = gcnew projectCSharpClass(); cl->String. But why do you want as String^ *, instead yust String^
-
Let's say you have a class in C#. And both project are under your solution. Go to c++/cli project setting, and add a reference by projects, and select a project c#. When in c++/cli: using namespace projectCSharNamespace; projectCSharpClass ^cl = gcnew projectCSharpClass(); cl->String. But why do you want as String^ *, instead yust String^
the C++/CLI function will be returning a value in the string passed in. sort of like in c# void GetName(ref string nameStr) { nameStr = "sam"; } in c++ it would be void GetName(string^ * nameStr) { *nameStr = "sam"; } The problem happened when I tried to call c++ from c# since c# doesn't understand * unless it's unsafe.
-
the C++/CLI function will be returning a value in the string passed in. sort of like in c# void GetName(ref string nameStr) { nameStr = "sam"; } in c++ it would be void GetName(string^ * nameStr) { *nameStr = "sam"; } The problem happened when I tried to call c++ from c# since c# doesn't understand * unless it's unsafe.
As i coud see with docmetation, (Nothing at all) And my test, i coud see that it isn't possible to do as reference. Why don't you use as return. If you wan't a multiple variables, you coud use struct. This coud be a bug, missing features or left out Intentionaly.
-
As i coud see with docmetation, (Nothing at all) And my test, i coud see that it isn't possible to do as reference. Why don't you use as return. If you wan't a multiple variables, you coud use struct. This coud be a bug, missing features or left out Intentionaly.
I figured it out. if you want to pass variables around as reference in C++/CLI you have to mark them with a %. so instead of void GetName(String ^ * name) { *name = "sam"; } you do this: void GetName(String^% name) { name = "Sam"; } then you call it from c# like this: String nameStr; GetName(ref nameStr);
-
I figured it out. if you want to pass variables around as reference in C++/CLI you have to mark them with a %. so instead of void GetName(String ^ * name) { *name = "sam"; } you do this: void GetName(String^% name) { name = "Sam"; } then you call it from c# like this: String nameStr; GetName(ref nameStr);