all groups > dotnet interop > december 2007 >
You're in the

dotnet interop

group:

C# seems not to understand pointer any more



C# seems not to understand pointer any more Peter
12/14/2007 5:29:21 PM
dotnet interop: We have code like this in our managed wrapper (written with managed
extensions in C++)

Byte * some_method();

which we compile with VS2003 to a managed assembly.

The functions in the assembly work nicely with C#/VB programs written with
VS2003, allowing unsafe code.

However, as soon as VS2005 is used to access these functions, the C#
compiler issues an error message of the kind that the language would not
support this construct.

Does anybody know what is going on here? Is this an issue with C# 2.0? How
can this be fixed?

Thanks.
Peter

Re: C# seems not to understand pointer any more Willy Denoyette [MVP]
12/14/2007 6:09:34 PM
[quoted text, click to view]


Please post the exact error message, it's not possible that the C# compiler
would show an error for a C++ module which isn't even compiled by the C#
compiler.
Not sure what you mean with "C#/VB programs written with VS2003, allowing
unsafe code." though, VB does not support unsafe code.


Willy.
Re: C# seems not to understand pointer any more Peter
12/16/2007 1:50:50 PM
I'm sorry, I was a bit unclear in my description.

1) We create an assembly with Managed Extensions for C++ named
some_name.dll. This assembly has source code like the following

Byte * some_method() // a method returning a pointer, defined within some
class
{
....
}

This assembly is created with VS2003, i.e. it is a .NET 1.1 assembly.

2) We then create an application in C# using the assembly of step 1. In this
application we try to use some_method from the assembly. When we compile
this application with C# in VS2003 everything is fine: the C# compiler
issues no error message and the function works as expected when executed.

3) When we compile the same C# code with C# in VS2005, the compiler issues
the error message: "language does not support this construct". Using other
methods which do not use pointers from the same assembly still works
properly.

I hope the desciption is clearer now.

Clearly something must have changed between C#/VS2003 and C#/VS2005 with
regards to using pointers. It would be instructive to know what has been
changed. Furthermore, how can the issue be dealt with and worked around?

Peter





AddThis Social Bookmark Button