Copying from IntPtr to struct
- From: Abhi <rkabhi@xxxxxxxxx>
- Date: Tue, 17 Jun 2008 13:43:18 -0700 (PDT)
Hi,
I am using pinvoke in the compact framework to implement some WZCSAPI
functions. It is working and I'm getting the required stuff from the
function, but it is in the form of a IntPtr which I need to copy to a
marshalled struct (WZC_802_11_CONFIG_LIST) which I have shown below.
When I try to copy from the IntPtr to the struct, I am getting an
exception like the below:
System.NotSupportedException was unhandled
Message="NotSupportedException"
<Code snippet>
[StructLayout(LayoutKind.Sequential)]
public struct WZC_WLAN_CONFIG
{
public uint Length;
public uint dwCtlFlags;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=6)]
public byte[] MacAddress;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public byte[] Reserved;
[MarshalAs(UnmanagedType.LPStruct)]
public NDIS_802_11_SSID Ssid;
public uint Privacy;
public uint Rssi;
public NDIS_802_11_NETWORK_TYPE NetworkTypeInUse;
[MarshalAs(UnmanagedType.LPStruct)]
public NDIS_802_11_CONFIGURATION Configuration;
public NDIS_802_11_NETWORK_INFRASTRUCTURE
InfrastructureMode;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[] SupportedRates;
public uint KeyIndex;
public uint KeyLength;
[MarshalAs(UnmanagedType.ByValArray, SizeConst =
WZCCTL_MAX_WEPK_MATERIAL)]
public byte[] KeyMaterial;
public NDIS_802_11_AUTHENTICATION_MODE AuthenticationMode;
public IntPtr rdUserData;
[MarshalAs(UnmanagedType.LPStruct)]
public WZC_EAPOL_PARAMS EapolParams;
public IntPtr rdNetworkData;
public uint WPAMCastCipher;
public uint ulMediaType;
}
struct WZC_802_11_CONFIG_LIST
{
public uint NumberOfItems; // number of elements in the
array below
public uint Index; // [start] index in the array
below
[MarshalAs(UnmanagedType.ByValArray, ArraySubType =
UnmanagedType.LPStruct, SizeConst = 1)]
public WZC_WLAN_CONFIG [] Config; // array of
WZC_WLAN_CONFIGs
}
[DllImport("wzcsapi.dll", SetLastError = true)]
private static extern uint WZCQueryInterfaceEx(
string pSrvAddr,
uint dwInFlags,
ref INTF_ENTRY_EX pIntfEx,
ref uint pdwOutFlags);
void function()
{
uint dwOutFlags = 0;
INTF_ENTRY_EX Intf = new INTF_ENTRY_EX();
//Marshal.(&Intf, 0x00, sizeof(INTF_ENTRY_EX));
Intf.wszGuid = szWiFiCard;
uint dwStatus = WZCQueryInterfaceEx(
null,
INTF_ALL,
ref Intf,
ref dwOutFlags);
if (dwStatus != 0)
{
string Error = "WZCEnumInterfaces() error 0x" +
dwStatus.ToString("X"); //ToString("X") converts to hex
MessageBox.Show(Error, "Error");
WZCDeleteIntfObjEx(ref Intf);
return;
}
byte[] data = new byte[Intf.rdStSSIDList.dwDataLen];
Marshal.Copy(Intf.rdStSSIDList.pData, data, 0,
(int)Intf.rdStSSIDList.dwDataLen);
GCHandle pinnedPacket = GCHandle.Alloc(data,
GCHandleType.Pinned);
WZC_802_11_CONFIG_LIST pConfigList = new
WZC_802_11_CONFIG_LIST();
pConfigList =
(WZC_802_11_CONFIG_LIST)Marshal.PtrToStructure(pinnedPacket.AddrOfPinnedObject(),
typeof(WZC_802_11_CONFIG_LIST));
}
</Code snippet>
.
- Prev by Date: Re: data binding with combobox
- Next by Date: RE: Deploy CF to a device along with the application
- Previous by thread: data binding with combobox
- Next by thread: Pinvoke of DirectShow in compact framework
- Index(es):
Relevant Pages
|