Enumerating connections

  • Thread starter Thread starter Steve B.
  • Start date Start date
S

Steve B.

Hi,

I'm trying to enumerate connnections on the device.

I've already write this code, but it throw a ArgumentNullException :

[DllImport("cellcore.dll",EntryPoint="ConnMgrEnumDestinations",SetLastError=true)]

private static extern int ConnMgrEnumDestinations(int nIndex, IntPtr
pDestinationInfo);

public static DestinationInfo[] EnumConnections()

{

IntPtr hDestInfo = IntPtr.Zero;

ArrayList result = new ArrayList();

while(ConnMgrEnumDestinations(result.Count, hDestInfo) != -2147467259) //
This line throw the exception

{

DestinationInfo di = new DestinationInfo();


di = (DestinationInfo)Marshal.PtrToStructure(

hDestInfo,

typeof(DestinationInfo)

);

result.Add(di);

}

return result.ToArray(typeof(DestinationInfo)) as DestinationInfo[];

}

[StructLayout(LayoutKind.Sequential)]

public struct DestinationInfo

{

Guid guid;

string description;

}



What's wrong with this code ?
 
Thanks, but I prefer creating my own "specific" classes instead of using
"generic" classes from OCF.
I took a look into the code of Open Net cf, but it is too much for what I
need.

I stepped a little :

hDestInfo = LocalAlloc(0x0040, 16 + 256);



This line has been added.

I can now enumerate connections, but I always get a "null" value for the
string. The guid seems to be correctly filled.



Thanks:

[DllImport("coredll.dll",EntryPoint="LocalAlloc",SetLastError=true)]

static extern IntPtr LocalAlloc(uint uFlags, uint Bytes);

[DllImport("coredll.dll",EntryPoint="LocalFree",SetLastError=true)]

static extern IntPtr LocalFree(IntPtr hMem);

[DllImport("cellcore.dll",EntryPoint="ConnMgrEnumDestinations",SetLastError=true)]

private static extern int ConnMgrEnumDestinations(int nIndex, IntPtr
pDestinationInfo);

public static DestinationInfo[] EnumConnections()

{

IntPtr hDestInfo = IntPtr.Zero;

ArrayList result = new ArrayList();

hDestInfo = LocalAlloc(0x0040, 16 + 256);

while(ConnMgrEnumDestinations(result.Count, hDestInfo) != -2147467259)

{

DestinationInfo di = new DestinationInfo();


di = (DestinationInfo)Marshal.PtrToStructure(

hDestInfo,

typeof(DestinationInfo)

);

result.Add(di);

}

LocalFree(hDestInfo);

return result.ToArray(typeof(DestinationInfo)) as DestinationInfo[];

}

[StructLayout(LayoutKind.Sequential)]

public struct DestinationInfo

{

Guid guid;

string description;

}


Peter Foot said:
You may want to take a look at the OpenNETCF code as this function is
already wrapped in there.
http://vault.netcf.tv/VaultService/VaultWeb/login.aspx
username guest, password guest

See OpenNETCF.Net.ConnectionManager

Peter

--
Peter Foot
Windows Embedded MVP
http://www.inthehand.com | http://www.peterfoot.net |
http://www.opennetcf.org

Steve B. said:
Hi,

I'm trying to enumerate connnections on the device.

I've already write this code, but it throw a ArgumentNullException :

[DllImport("cellcore.dll",EntryPoint="ConnMgrEnumDestinations",SetLastError=true)]

private static extern int ConnMgrEnumDestinations(int nIndex, IntPtr
pDestinationInfo);

public static DestinationInfo[] EnumConnections()

{

IntPtr hDestInfo = IntPtr.Zero;

ArrayList result = new ArrayList();

while(ConnMgrEnumDestinations(result.Count, hDestInfo) != -2147467259) //
This line throw the exception

{

DestinationInfo di = new DestinationInfo();


di = (DestinationInfo)Marshal.PtrToStructure(

hDestInfo,

typeof(DestinationInfo)

);

result.Add(di);

}

return result.ToArray(typeof(DestinationInfo)) as DestinationInfo[];

}

[StructLayout(LayoutKind.Sequential)]

public struct DestinationInfo

{

Guid guid;

string description;

}



What's wrong with this code ?
 
Thats why I suggested looking at the source code - so that you can pick and
choose what you want for your specific requirements.

Peter

--
Peter Foot
Windows Embedded MVP
http://www.inthehand.com | http://www.peterfoot.net |
http://www.opennetcf.org

Steve B. said:
Thanks, but I prefer creating my own "specific" classes instead of using
"generic" classes from OCF.
I took a look into the code of Open Net cf, but it is too much for what I
need.

I stepped a little :

hDestInfo = LocalAlloc(0x0040, 16 + 256);



This line has been added.

I can now enumerate connections, but I always get a "null" value for the
string. The guid seems to be correctly filled.



Thanks:

[DllImport("coredll.dll",EntryPoint="LocalAlloc",SetLastError=true)]

static extern IntPtr LocalAlloc(uint uFlags, uint Bytes);

[DllImport("coredll.dll",EntryPoint="LocalFree",SetLastError=true)]

static extern IntPtr LocalFree(IntPtr hMem);

[DllImport("cellcore.dll",EntryPoint="ConnMgrEnumDestinations",SetLastError=true)]

private static extern int ConnMgrEnumDestinations(int nIndex, IntPtr
pDestinationInfo);

public static DestinationInfo[] EnumConnections()

{

IntPtr hDestInfo = IntPtr.Zero;

ArrayList result = new ArrayList();

hDestInfo = LocalAlloc(0x0040, 16 + 256);

while(ConnMgrEnumDestinations(result.Count, hDestInfo) != -2147467259)

{

DestinationInfo di = new DestinationInfo();


di = (DestinationInfo)Marshal.PtrToStructure(

hDestInfo,

typeof(DestinationInfo)

);

result.Add(di);

}

LocalFree(hDestInfo);

return result.ToArray(typeof(DestinationInfo)) as DestinationInfo[];

}

[StructLayout(LayoutKind.Sequential)]

public struct DestinationInfo

{

Guid guid;

string description;

}


Peter Foot said:
You may want to take a look at the OpenNETCF code as this function is
already wrapped in there.
http://vault.netcf.tv/VaultService/VaultWeb/login.aspx
username guest, password guest

See OpenNETCF.Net.ConnectionManager

Peter

--
Peter Foot
Windows Embedded MVP
http://www.inthehand.com | http://www.peterfoot.net |
http://www.opennetcf.org

Steve B. said:
Hi,

I'm trying to enumerate connnections on the device.

I've already write this code, but it throw a ArgumentNullException :

[DllImport("cellcore.dll",EntryPoint="ConnMgrEnumDestinations",SetLastError=true)]

private static extern int ConnMgrEnumDestinations(int nIndex, IntPtr
pDestinationInfo);

public static DestinationInfo[] EnumConnections()

{

IntPtr hDestInfo = IntPtr.Zero;

ArrayList result = new ArrayList();

while(ConnMgrEnumDestinations(result.Count, hDestInfo) != -2147467259)
// This line throw the exception

{

DestinationInfo di = new DestinationInfo();


di = (DestinationInfo)Marshal.PtrToStructure(

hDestInfo,

typeof(DestinationInfo)

);

result.Add(di);

}

return result.ToArray(typeof(DestinationInfo)) as DestinationInfo[];

}

[StructLayout(LayoutKind.Sequential)]

public struct DestinationInfo

{

Guid guid;

string description;

}



What's wrong with this code ?
 
Back
Top