J
jonfroehlich
How can I marshal C# strings to C++ ANSI char* and vice versa? For
example, I am dealing with the following C++ struct.
/**
* WPS_SimpleAuthentication is used to identify
* the user with the server.
*/
typedef struct
{
/**
* the user's name, or unique identifier.
*/
const char* username;
/**
* the authentication realm
*/
const char* realm;
} WPS_SimpleAuthentication;
I would like to call this C++ function:
extern WPS_ReturnCode SimplifiedFunction(const
WPS_SimpleAuthentication* authentication);
The analog C# struct with the full .NET Framework is:
// simple authentication, only used for sending information out.
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct WPS_SimpleAuthentication
{
public String username;
public String realm;
//constructor
public WPS_SimpleAuthentication(String username, String realm)
{
this.username = username;
this.realm = realm;
}
}
However, .NET CF does not have CharSet.Ansi. What should I do?
As a follow up, I also need to be able to Marshal C++ ANSI char* back
to C# string types. For example, how would I do this?
string example =
Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(int_street_addr.address_line))
Oh and forgive me if I am not using the "Marshal" word here in the
right way.
Thanks!
Jon
example, I am dealing with the following C++ struct.
/**
* WPS_SimpleAuthentication is used to identify
* the user with the server.
*/
typedef struct
{
/**
* the user's name, or unique identifier.
*/
const char* username;
/**
* the authentication realm
*/
const char* realm;
} WPS_SimpleAuthentication;
I would like to call this C++ function:
extern WPS_ReturnCode SimplifiedFunction(const
WPS_SimpleAuthentication* authentication);
The analog C# struct with the full .NET Framework is:
// simple authentication, only used for sending information out.
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct WPS_SimpleAuthentication
{
public String username;
public String realm;
//constructor
public WPS_SimpleAuthentication(String username, String realm)
{
this.username = username;
this.realm = realm;
}
}
However, .NET CF does not have CharSet.Ansi. What should I do?
As a follow up, I also need to be able to Marshal C++ ANSI char* back
to C# string types. For example, how would I do this?
string example =
Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(int_street_addr.address_line))
Oh and forgive me if I am not using the "Marshal" word here in the
right way.
Thanks!
Jon