C
Chris Ellis
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
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