pinvoke question

S

Sagaert Johan

Hi

i have some problems p invoking this :

HRESULT WINAPI ConnMgrEnumDestinations(
int Index,
CONNMGR_DESTINATION_INFO *pDestInfo
); i converted this to :[DllImport("CellCore.dll")]static extern int
ConnMgrEnumDestinations(int Index, ref CONNMGR_DESTINATION_INFO pDestInfo);
i tried to convert this structure typedef struct {
GUID guid;
TCHAR szDescription[CONNMGR_MAX_DESC];
BOOL fSecure;
} CONNMGR_DESTINATION_INFO;as[StructLayout(LayoutKind.Sequential)]class
CONNMGR_DESTINATION_INFO{ public Guid guid= Guid.Empty; public char[]
szDescription; public bool fSecure=false; public
CONNMGR_DESTINATION_INFO() { szDescription = new char[128]; }}i
tried to use the function on my WM5 device :CONNMGR_DESTINATION_INFO ci =new
CONNMGR_DESTINATION_INFO();int ret=ConnMgrEnumDestinations(0, ref ci); Can
someone help me on this ?Johan
 
P

Peter Foot

A couple of things, you have defined the native structure as a class which
will marshal it by reference by default. Secondly you need to specify the
marshalling of the inline string, and fSecure is a BOOL (32bit):-

[DllImport("CellCore.dll")]
static extern int ConnMgrEnumDestinations(int Index, out
CONNMGR_DESTINATION_INFO pDestInfo);

[StructLayout(LayoutKind.Sequential)]
struct CONNMGR_DESTINATION_INFO
{
public Guid guid;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=128)]
public string szDescription;
[MarshalAs(UnmanagedType.Bool)]
public bool fSecure;
}

usage:-

CONNMGR_DESTINATION_INFO ci = new CONNMGR_DESTINATION_INFO();
int ret=ConnMgrEnumDestinations(0, ref ci);

Peter
 
S

Sagaert Johan

Thanks !!
It works now.

Peter Foot said:
A couple of things, you have defined the native structure as a class which
will marshal it by reference by default. Secondly you need to specify the
marshalling of the inline string, and fSecure is a BOOL (32bit):-

[DllImport("CellCore.dll")]
static extern int ConnMgrEnumDestinations(int Index, out
CONNMGR_DESTINATION_INFO pDestInfo);

[StructLayout(LayoutKind.Sequential)]
struct CONNMGR_DESTINATION_INFO
{
public Guid guid;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=128)]
public string szDescription;
[MarshalAs(UnmanagedType.Bool)]
public bool fSecure;
}

usage:-

CONNMGR_DESTINATION_INFO ci = new CONNMGR_DESTINATION_INFO();
int ret=ConnMgrEnumDestinations(0, ref ci);

Peter

--
Peter Foot
Microsoft Device Application Development MVP
www.peterfoot.net | www.inthehand.com
In The Hand Ltd - .NET Solutions for Mobility

Sagaert Johan said:
Hi

i have some problems p invoking this :

HRESULT WINAPI ConnMgrEnumDestinations(
int Index,
CONNMGR_DESTINATION_INFO *pDestInfo
); i converted this to :[DllImport("CellCore.dll")]static extern int
ConnMgrEnumDestinations(int Index, ref CONNMGR_DESTINATION_INFO
pDestInfo); i tried to convert this structure typedef struct {
GUID guid;
TCHAR szDescription[CONNMGR_MAX_DESC];
BOOL fSecure;
} CONNMGR_DESTINATION_INFO;as[StructLayout(LayoutKind.Sequential)]class
CONNMGR_DESTINATION_INFO{ public Guid guid= Guid.Empty; public
char[] szDescription; public bool fSecure=false; public
CONNMGR_DESTINATION_INFO() { szDescription = new r[128]; }}i
tried to use the function on my WM5 device :CONNMGR_DESTINATION_INFO ci
=new CONNMGR_DESTINATION_INFO();int ret=ConnMgrEnumDestinations(0, ref
ci); Can someone help me on this ?Johan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top