Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / February 2007

Tip: Looking for answers? Try searching our database.

frustrating parameter issue

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vinz - 26 Feb 2007 22:40 GMT
Hello everyone,

My question is part C# and part C++. Please don't kill me for bringing C#
inhere :-) Also please don't kill me for asking a n00b question, I'm still
new to C++/CLI and C#.

I have an assembly written in C++/CLI with a public function:

int MyClass::MyFunction(String ^x) {
   x = "zzz";
   return 0;
};

I want to call this function from a C# app and show the changed contents of
variable

MyClass TheClass = new MyClass();
String w = "m";
TheClass.MyFunction(w);
MessageBox.Show(w);

When executing, the messagebox shows 'm', and I want it to show 'zzz'.

What am I doing wrong here???

Thanks for reading sofar.

Vince.
David Lowndes - 26 Feb 2007 23:03 GMT
>I want to call this function from a C# app and show the changed contents of
>variable

Vince,

You need to define the function parameter as a tracking reference -
see "% Tracking Reference" in MSDN.

Dave
David Anton - 26 Feb 2007 23:25 GMT
int MyClass::MyFunction(String ^%x) {
   x = "zzz";
   return 0;
};

Signature

David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter

> Hello everyone,
>
[quoted text clipped - 24 lines]
>
> Vince.
Vinz - 27 Feb 2007 07:01 GMT
Thanks very much guys :-)

I tried to use the % before but that doesn't compile. ^% compiles though. I
had to also use ref x instead of just x in the C# call too btw.

Anyway, I got it working now, thanks a lot :-)

Vince.

> int MyClass::MyFunction(String ^%x) {
>    x = "zzz";
[quoted text clipped - 31 lines]
>>
>> Vince.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.