473,387 Members | 1,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

mixed-mode C++ and the Out attribute

Hi,

I'm not sure if this is the right newsgroup for this question. I'm not
sure if the problem lies in C# or in C++, but I am working on a project that
uses a mixed-mode C++ dll to wrap some API's into classes. I am then using
those classes from a library in C#. In one of my C++ functions, I wanted to
use an out parameter. This is the code that I used to declare/define that
function:

// declaration
Stream* OpenOrCreateStream( String* Name,
[System::Runtime::InteropServices::Out] bool* bCreated );

// definition

StructuredStorage::Stream* StructuredStorage::Storage::OpenOrCreateStream(
String* Name, [System::Runtime::InteropServices::Out] bool* bCreated )
{
...
}

this compiles fine and the definition of the function as shown by ildasm is
as follows:

..method public instance class StructuredStorage.Stream
OpenOrCreateStream(string Name,
[out] bool* bCreated) cil managed

now, in C#, I call that function in the following statemen:

Stream sProt = m_Database.OpenOrCreateStream( PROTECTION_STREAM, out
bCreated );

and that yields me the following error:

error CS1503: Argument '2': cannot convert from 'out bool' to 'bool*'

and when intellisense shows me the function arguments in C#, it shows:
string, bool*

I seem to be following the documentation on the Out attribute exactly and I
have no idea why this is causing me a problem. Currently, my only solution
is to enable unsafe code in C# and call the function passing the address of
a boolean variable, but I would far prefer to do it using the out parameter.
Does anyone see what I'm doing wrong or is this a known problem?

Please let me know if you need any more info. I provided everything I could
think of... oh.... I'm using .NET 1.1 in Visual Studio 2003.

Thanks in advance,
Chris
Nov 17 '05 #1
3 4374
Jon
Try:

Stream* OpenOrCreateStream( String* Name,[Out] bool _gc* bCreated );

"Chris Ellis" <praiseGod777@RemoveThis_hotmail.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,

I'm not sure if this is the right newsgroup for this question. I'm not
sure if the problem lies in C# or in C++, but I am working on a project that
uses a mixed-mode C++ dll to wrap some API's into classes. I am then using
those classes from a library in C#. In one of my C++ functions, I wanted to
use an out parameter. This is the code that I used to declare/define that
function:

// declaration
Stream* OpenOrCreateStream( String* Name,
[System::Runtime::InteropServices::Out] bool* bCreated );

// definition

StructuredStorage::Stream* StructuredStorage::Storage::OpenOrCreateStream(
String* Name, [System::Runtime::InteropServices::Out] bool* bCreated )
{
...
}

this compiles fine and the definition of the function as shown by ildasm is
as follows:

.method public instance class StructuredStorage.Stream
OpenOrCreateStream(string Name,
[out] bool* bCreated) cil managed

now, in C#, I call that function in the following statemen:

Stream sProt = m_Database.OpenOrCreateStream( PROTECTION_STREAM, out
bCreated );

and that yields me the following error:

error CS1503: Argument '2': cannot convert from 'out bool' to 'bool*'

and when intellisense shows me the function arguments in C#, it shows:
string, bool*

I seem to be following the documentation on the Out attribute exactly and I
have no idea why this is causing me a problem. Currently, my only solution
is to enable unsafe code in C# and call the function passing the address of
a boolean variable, but I would far prefer to do it using the out parameter.
Does anyone see what I'm doing wrong or is this a known problem?

Please let me know if you need any more info. I provided everything I could
think of... oh.... I'm using .NET 1.1 in Visual Studio 2003.

Thanks in advance,
Chris

Nov 17 '05 #2
Jon,

Thank you. That did the trick. I'm honestly not certain why. I was
under the assumption that __gc related only to objects that are garbage
collected, but unless this is referring to a bool on the garbage collected
heap, it appears that my assumption was not correct.

Thanks again,
Chris

"Jon" <Jo*@martinsound.com> wrote in message
news:O5**************@tk2msftngp13.phx.gbl...
Try:

Stream* OpenOrCreateStream( String* Name,[Out] bool _gc* bCreated );

"Chris Ellis" <praiseGod777@RemoveThis_hotmail.com> wrote in message

news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,

I'm not sure if this is the right newsgroup for this question. I'm not sure if the problem lies in C# or in C++, but I am working on a project that uses a mixed-mode C++ dll to wrap some API's into classes. I am then using those classes from a library in C#. In one of my C++ functions, I wanted to use an out parameter. This is the code that I used to declare/define that function:

// declaration
Stream* OpenOrCreateStream( String* Name,
[System::Runtime::InteropServices::Out] bool* bCreated );

// definition

StructuredStorage::Stream* StructuredStorage::Storage::OpenOrCreateStream( String* Name, [System::Runtime::InteropServices::Out] bool* bCreated )
{
...
}

this compiles fine and the definition of the function as shown by ildasm is as follows:

.method public instance class StructuredStorage.Stream
OpenOrCreateStream(string Name,
[out] bool* bCreated) cil managed

now, in C#, I call that function in the following statemen:

Stream sProt = m_Database.OpenOrCreateStream( PROTECTION_STREAM, out
bCreated );

and that yields me the following error:

error CS1503: Argument '2': cannot convert from 'out bool' to 'bool*'

and when intellisense shows me the function arguments in C#, it shows:
string, bool*

I seem to be following the documentation on the Out attribute exactly and I have no idea why this is causing me a problem. Currently, my only solution is to enable unsafe code in C# and call the function passing the address of a boolean variable, but I would far prefer to do it using the out parameter. Does anyone see what I'm doing wrong or is this a known problem?

Please let me know if you need any more info. I provided everything I could think of... oh.... I'm using .NET 1.1 in Visual Studio 2003.

Thanks in advance,
Chris


Nov 17 '05 #3
It's more accurate to say that __gc relates to objects that *may* be on the
garbage collected heap. (For example, consider the case where you have a
bool inside a __gc class -- a pointer to that bool will point to a location
under garbage collector control -- so having a __nogc * for this is
absolutely forbidden.) In fact there is an implicit conversion from a __nogc
pointer to a __value type to a __gc pointer to the __value type -- i.e., if
I have a bool __nogc *, then I can pass it to your routine expecting a bool
__gc *.

There's useful info on this here:
<ms-help://MS.MSDNQTR.2003FEB.1033/vcmxspec/html/vcManagedExtensionsSpec_7_2
..htm>
"Chris Ellis" <praiseGod777@RemoveThis_hotmail.com> wrote in message
news:OI**************@tk2msftngp13.phx.gbl...
Jon,

Thank you. That did the trick. I'm honestly not certain why. I was
under the assumption that __gc related only to objects that are garbage
collected, but unless this is referring to a bool on the garbage collected
heap, it appears that my assumption was not correct.

Thanks again,
Chris

"Jon" <Jo*@martinsound.com> wrote in message
news:O5**************@tk2msftngp13.phx.gbl...
Try:

Stream* OpenOrCreateStream( String* Name,[Out] bool _gc* bCreated );

"Chris Ellis" <praiseGod777@RemoveThis_hotmail.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,

I'm not sure if this is the right newsgroup for this question.
I'm not sure if the problem lies in C# or in C++, but I am working on a
project
that uses a mixed-mode C++ dll to wrap some API's into classes. I am then using those classes from a library in C#. In one of my C++ functions, I wanted to use an out parameter. This is the code that I used to declare/define that function:

// declaration
Stream* OpenOrCreateStream( String* Name,
[System::Runtime::InteropServices::Out] bool* bCreated );

// definition

StructuredStorage::Stream* StructuredStorage::Storage::OpenOrCreateStream( String* Name, [System::Runtime::InteropServices::Out] bool* bCreated )
{
...
}

this compiles fine and the definition of the function as shown by
ildasm
is as follows:

.method public instance class StructuredStorage.Stream
OpenOrCreateStream(string Name,
[out] bool* bCreated) cil managed

now, in C#, I call that function in the following statemen:

Stream sProt = m_Database.OpenOrCreateStream( PROTECTION_STREAM, out
bCreated );

and that yields me the following error:

error CS1503: Argument '2': cannot convert from 'out bool' to 'bool*'

and when intellisense shows me the function arguments in C#, it shows:
string, bool*

I seem to be following the documentation on the Out attribute exactly and I have no idea why this is causing me a problem. Currently, my only solution is to enable unsafe code in C# and call the function passing the
address
of a boolean variable, but I would far prefer to do it using the out parameter. Does anyone see what I'm doing wrong or is this a known problem?

Please let me know if you need any more info. I provided everything I could think of... oh.... I'm using .NET 1.1 in Visual Studio 2003.

Thanks in advance,
Chris



Nov 17 '05 #4

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

Similar topics

3
by: Perttu Pulkkinen | last post by:
No questions, but just consider if this is useful to you:-) but of course feedback & corrections are welcome. function php_mixed_to_js_value($jsname, $mixed) { if(is_null($mixed)) { return "\n...
0
by: Swaroop Kumar | last post by:
Hi: I'm trying to write a schema that contains information as described below: 1. The first element is a mandatory fixed string. 2. The second element is a mixed content element that can...
2
by: Paul A. Hoadley | last post by:
Hello, I am trying to convert a RELAX NG schema to DTD using Trang. I am currently trying to add some inline elements to the schema, such as <emph> for marking emphasised text. Here is an...
46
by: James Harris | last post by:
Before I embark on a new long-term project I'd appreciate your advice on how to split up long names. I would like to keep the standards for command names the same as that for variable names....
2
by: bearophileHUGS | last post by:
Notes: - This email is about Mark Dufour's Shed Skin (SS) (http://shed-skin.blogspot.com), but the errors/ingenuousness it contains are mine. My experience with C++ is limited still. - The...
1
by: Colin Desmond | last post by:
I have a dll assembly compiler with the /clr flag as it contains ref classes and traditional style C++ classes. I want to write unit tests for the ref classes in that assembly. VS2005 allows me...
4
by: natG | last post by:
Hi; I am transferring data from MySql to db2 using my own java/jdbc program. Working out ok, except for the fact that our apps use mixed-case names for tables and columns. Although my CREATE TABLE...
1
by: bvisscher | last post by:
I posted this recently in microsoft.public.vc.language and was redirected here. I also searched this ng and found some relavant threads. The most relavent I found was: ...
1
by: =?Utf-8?B?SmltIFdhbHNo?= | last post by:
I have an VC++ MFC Win32 application that isn't working correctly when I build it with VS2005. The problem seems to be in some ADO ActiveX controls that came with VS6 and are now out of support....
7
by: =?Utf-8?B?SmltIFdhbHNo?= | last post by:
I'm new to working with mixed assemblies. All of my previous experience has been with VC++/MFC in native, unmanaged applications. When I create a mixed assembly in which one or more of the files...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.