473,499 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to ? out argument in managed c++

Hello gurus,

I have the following C# function signature:
void TheFunction(Dictionary<string, MyClassObjdicName, 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?
--
Thanks
Sharon
Jun 21 '07 #1
4 3676

"Sharon" <Sh*****@newsgroups.nospamwrote in message
news:A2**********************************@microsof t.com...
Hello gurus,

I have the following C# function signature:
void TheFunction(Dictionary<string, MyClassObjdicName, 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?
For VC++ 2005 (C++/CLI):

void TheFunction( System::Collections::Generic::Dictionary<System::S tring^,
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.

>

--
Thanks
Sharon
Jun 21 '07 #2
Thanks Ben,

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

Your solution works fine.

---------
Thanks a lot
Sharon
Jun 22 '07 #3
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::S tring^,
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?
--
Thanks
Sharon
Jun 23 '07 #4
Sharon wrote:
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::S tring^,
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?
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::S tring^,
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
Jun 23 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1719
by: mrambil | last post by:
Hi, I'm using PHP 4.3.3 in CLI on Win XP SP1. I use the _experimental_ w32api. It seems to work quite fine yet I cannot pass a string argument to any of my dll functions : 1) Load the w32api...
64
3311
by: Morgan Cheng | last post by:
Hi All, I was taught that argument valuse is not supposed to be changed in function body. Say, below code is not good. void foo1(int x) { x ++; printf("x+1 = %d\n", x); } It should be...
11
1924
by: j23 | last post by:
I have library (static) testlib.cpp: #include <stdarg.h> void xxx(...) { char buf; va_list args; va_start(args, buf); va_end(args); }
0
958
by: Steve Terepin | last post by:
I've got a Managed C++ class that's being called from C#, and the C# code needs to look like this : byte * p = myManagedCppClassInstance.AllocateDmaBuffer(1000) ; // Do various things, then ......
2
1315
by: Chris | last post by:
Hi, how can I use variable argument lists in C++.NET (cfr 'params' in C#) ? thnx Chris
5
1554
by: kchui | last post by:
I have a C# interface as: public interface IBar{ void TestParam(ref StringCollection a, ref int b); } And I need to implment it in Managed C++, and I try to implement it as: public __gc...
5
3071
by: nass | last post by:
this is a thought experiment. i do not have the time to implement it and test it to see if it works so i am relying on your good will:) thank you in advance im on a linux machine (slackware...
3
4325
by: vijay.gandhi | last post by:
Hi, I am trying to convert a set of classes written in VC++ 6.0 to a .DLL file using VC++ .NET (Visual Studio 2005) and C++/CLI. I made one of the classes (one at the root level) to be a 'ref'...
6
1635
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hello gurus, I have the following C# function signature: void TheFunction(Dictionary<string, MyClassObjdicName, out int nOne, out int nTwo, out int nThree, out int nFour); And it works fine....
23
3241
by: nikki2 | last post by:
Hi I have a database, with which I have always had problems. Sometimes they were Invalid Argument problems, and sometimes there were others (such as that the record was too large). Some of the...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7225
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7392
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5479
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4920
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4605
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3105
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
307
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.