> 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