Reputation:
Can anyone please tell me why compiling a C# application with a .cs file containing the following piece of code is giving me an error . See below.
namespace defintions
{
unsafe public struct name
{
char* firstname;
char* lastname;
} ;
class Functions
{
[DllImport("C++Dll.dll")]
public unsafe static extern long func(name *); //error : Identifier expected
}
}
Upvotes: 0
Views: 753
Reputation: 5853
You don't have to use unsafe code in your example. A class is always marshalled by reference to unmanaged code. Try this:
namespace defintions
{
public class name
{
[MarshalAs(UnmanagedType.LPStr)]
string firstname;
[MarshalAs(UnmanagedType.LPStr)]
string lastname;
}
class Functions
{
[DllImport("C++Dll.dll")]
public static extern long func(name theName);
}
}
Upvotes: 3
Reputation: 31878
Your function's parameter doesn't have a name (name * isn't a name).
Change it to
[DllImport("C++Dll.dll")]
public unsafe static extern long func(name* theName); //error : Identifier expected
Upvotes: 8