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++ / June 2007

Tip: Looking for answers? Try searching our database.

How to ? out argument in managed c++

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sharon - 21 Jun 2007 21:49 GMT
Hello gurus,

I have the following C# function signature:
void TheFunction(Dictionary<string, MyClassObj> dicName, out int nOne, out
int nTwo, out int nThree, out int nFour);

And it works fine.

I'm trying to write a managed C++ function that will save the save
signature, but till now I've got all kind of compiler error.

Can anyone tell me how a managed C++ function signature should look like
that will do the job like the one I showed above?

Signature

Thanks
Sharon

Ben Voigt [C++ MVP] - 22 Jun 2007 00:01 GMT
> Hello gurus,
>
[quoted text clipped - 9 lines]
> Can anyone tell me how a managed C++ function signature should look like
> that will do the job like the one I showed above?

For VC++ 2005 (C++/CLI):

void TheFunction( System::Collections::Generic::Dictionary<System::String^,
MyClassObj^>^ dicName, [System::RuntimeServices::Interop::Out] int% nOne,
[System::RuntimeServices::Interop::Out] int% nTwo,
[System::RuntimeServices::Interop::Out] int% nThree,
[System::RuntimeServices::Interop::Out] int% nFour);

For VC++ 2002/2003 (Managed Extensions for C++):

Buggy, won't be fixed.  Upgrade to VC++ 2005.  Don't complain about price,
Express edition is free.
Sharon - 22 Jun 2007 10:31 GMT
Thanks Ben,

I 'm using the Framework 2. Sorry for not pointing that our earlier.

Your solution works fine.

---------
Thanks a lot
Sharon
Sharon - 23 Jun 2007 08:00 GMT
Hi Ben,

The function signature still works but I have strange problem checking if
the dicName is null or not...

In the function (VC++ 2005 (C++/CLI)):

void TheFunction( System::Collections::Generic::Dictionary<System::String^,
MyClassObj^>^ dicName, [System::RuntimeServices::Interop::Out] int% nOne,
[System::RuntimeServices::Interop::Out] int% nTwo,
[System::RuntimeServices::Interop::Out] int% nThree,
[System::RuntimeServices::Interop::Out] int% nFour)
{
   if( dicName != NULL ) // Error
   {
       if( dicName ["key"] != NULL ) // Error
       {
           ...
       }
       ...
   }
}

I tried some other ways to check it, but I'm still getting all kind of
compiler error.

How do I check if it's null or not if the above two cases?

Signature

Thanks
Sharon

Carl Daniel [VC++ MVP] - 23 Jun 2007 21:34 GMT
> Hi Ben,
>
[quoted text clipped - 23 lines]
>
> How do I check if it's null or not if the above two cases?

NULL is a macro #defined to be 0.  As you've discovered, you can't compare a
managed reference to 0.  Instead, C++/CLI adds a new named constant,
nullptr, for just this purpose.  You can also use nullptr in unmanaged code,
and it's expected to be an official part of the next C++ standard ("C++
09").

Also, a point of usage of Dictionary<TKey,TVal>:  To check for the presense
of an item, use the ContainsKey member function, rather than using the
indexer (operator []).  Using the indexer will actuall add the key to the
dictionary and associate it with a null object reference.  So:

void TheFunction( System::Collections::Generic::Dictionary<System::String^,
MyClassObj^>^ dicName, [System::RuntimeServices::Interop::Out] int% nOne,
[System::RuntimeServices::Interop::Out] int% nTwo,
[System::RuntimeServices::Interop::Out] int% nThree,
[System::RuntimeServices::Interop::Out] int% nFour)
{
   if( dicName != nullptr)
   {
       if( dicName->ContainsKey("key"))
       {
           ...
       }
       ...
   }
}

-cd

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.