|
From: Abhi on 13 Jun 2008 21:30 Hi, I am trying to use the native WinCE API WZCEnumInterfaces using interop in C# .NET compact framework. I have to develop this without the OpenNetCF wrapper. But whenever I call the function, I get the exception "System.NotSupportedException". I looked at the help page for this exception and I think I have taken care of all the possible causes for the exception. Could anyone please let me know anything that I could be doing wrong. Please find my code below: [StructLayout(LayoutKind.Sequential)] struct INTF_KEY_ENTRY { [MarshalAs(UnmanagedType.LPWStr)] public string wszGuid; } [StructLayout(LayoutKind.Sequential)] struct INTFS_KEY_TABLE { public uint dwNumIntfs; public IntPtr pIntfs; //This is a pointer to INTF_KEY_ENTRY in the native c++ } [DllImport("wzcsapi.dll", SetLastError = true)] private static extern ulong WZCEnumInterfaces(string pSrvAddr, ref INTFS_KEY_TABLE pIntfs); /// <summary> /// find the first wireless network cards /// </summary> public void GetFirstWirelessNetworkCard() { INTFS_KEY_TABLE IntfsTable = new INTFS_KEY_TABLE(); IntfsTable.dwNumIntfs = 0; IntfsTable.pIntfs = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)) * (int)IntfsTable.dwNumIntfs); ulong dwStatus = 0; try { dwStatus = WZCEnumInterfaces(null , ref IntfsTable); } catch(Exception e) { int errorNum = Marshal.GetLastWin32Error(); MessageBox.Show(e.Message + " Error: " + errorNum, "Fatal Error!"); return; } }
From: Abhi on 13 Jun 2008 21:57 Now I have made the following changes to the initial declarations in my function. But I am still getting the same error. INTFS_KEY_TABLE IntfsTable = new INTFS_KEY_TABLE(); INTF_KEY_ENTRY IntfsEntry = new INTF_KEY_ENTRY(); IntfsEntry.wszGuid = string.Empty; IntfsTable.dwNumIntfs = 0; IntfsTable.pIntfs = Marshal.AllocHGlobal(Marshal.SizeOf(IntfsEntry)); Marshal.StructureToPtr(IntfsEntry, IntfsTable.pIntfs, false); On 13 Jun, 19:30, Abhi <rka...(a)gmail.com> wrote: > Hi, > > I am trying to use the native WinCE API WZCEnumInterfaces using > interop in C# .NET compact framework. I have to develop this without > the OpenNetCF wrapper. But whenever I call the function, I get the > exception "System.NotSupportedException". I looked at the help page > for this exception and I think I have taken care of all the possible > causes for the exception. Could anyone please let me know anything > that I could be doing wrong. Please find my code below: > > [StructLayout(LayoutKind.Sequential)] > struct INTF_KEY_ENTRY > { > [MarshalAs(UnmanagedType.LPWStr)] > public string wszGuid; > } > > [StructLayout(LayoutKind.Sequential)] > struct INTFS_KEY_TABLE > { > public uint dwNumIntfs; > > public IntPtr pIntfs; //This is a pointer to > INTF_KEY_ENTRY in the native c++ > } > > [DllImport("wzcsapi.dll", SetLastError = true)] > private static extern ulong WZCEnumInterfaces(string pSrvAddr, > ref INTFS_KEY_TABLE pIntfs); > > /// <summary> > /// find the first wireless network cards > /// </summary> > public void GetFirstWirelessNetworkCard() > { > INTFS_KEY_TABLE IntfsTable = new > INTFS_KEY_TABLE(); > IntfsTable.dwNumIntfs = 0; > > IntfsTable.pIntfs = > Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)) * > (int)IntfsTable.dwNumIntfs); > > ulong dwStatus = 0; > > try > { > dwStatus = WZCEnumInterfaces(null , ref IntfsTable); > } > catch(Exception e) > { > int errorNum = Marshal.GetLastWin32Error(); > > MessageBox.Show(e.Message + " Error: " + errorNum, > "Fatal Error!"); > return; > } > }
From: Chris Tacke, MVP on 13 Jun 2008 22:50 So why exactly are you wasting time doing this and not using OpenNETCF's implementation? It comes with full source if you buy the extensions, and it seems to me that if you've spent more than 30 minutes already trying to get this working, then it's worth the $50 to just purchase it. -Chris "Abhi" <rkabhi(a)gmail.com> wrote in message news:2687bf9e-c17d-4190-8b3a-637bbe8ec4dc(a)x35g2000hsb.googlegroups.com... > Hi, > > I am trying to use the native WinCE API WZCEnumInterfaces using > interop in C# .NET compact framework. I have to develop this without > the OpenNetCF wrapper. But whenever I call the function, I get the > exception "System.NotSupportedException". I looked at the help page > for this exception and I think I have taken care of all the possible > causes for the exception. Could anyone please let me know anything > that I could be doing wrong. Please find my code below: > > [StructLayout(LayoutKind.Sequential)] > struct INTF_KEY_ENTRY > { > [MarshalAs(UnmanagedType.LPWStr)] > public string wszGuid; > } > > [StructLayout(LayoutKind.Sequential)] > struct INTFS_KEY_TABLE > { > public uint dwNumIntfs; > > public IntPtr pIntfs; //This is a pointer to > INTF_KEY_ENTRY in the native c++ > } > > [DllImport("wzcsapi.dll", SetLastError = true)] > private static extern ulong WZCEnumInterfaces(string pSrvAddr, > ref INTFS_KEY_TABLE pIntfs); > > /// <summary> > /// find the first wireless network cards > /// </summary> > public void GetFirstWirelessNetworkCard() > { > INTFS_KEY_TABLE IntfsTable = new > INTFS_KEY_TABLE(); > IntfsTable.dwNumIntfs = 0; > > IntfsTable.pIntfs = > Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)) * > (int)IntfsTable.dwNumIntfs); > > ulong dwStatus = 0; > > try > { > dwStatus = WZCEnumInterfaces(null , ref IntfsTable); > } > catch(Exception e) > { > int errorNum = Marshal.GetLastWin32Error(); > > MessageBox.Show(e.Message + " Error: " + errorNum, > "Fatal Error!"); > return; > } > }
From: Abhi on 17 Jun 2008 15:34 The problem was that I had the return type of the function as a 64-bit ulong. When I tried 32-bit uint, it worked. Also I downloaded the opennetcf libraries like you suggested. Thanks, Abhi On 13 Jun, 20:50, "Chris Tacke, MVP" <ctacke.at.opennetcf.dot.com> wrote: > So why exactly are you wasting time doing this and not using OpenNETCF's > implementation? It comes with full source if you buy the extensions, and it > seems to me that if you've spent more than 30 minutes already trying to get > this working, then it's worth the $50 to just purchase it. > > -Chris > > "Abhi" <rka...(a)gmail.com> wrote in message > > news:2687bf9e-c17d-4190-8b3a-637bbe8ec4dc(a)x35g2000hsb.googlegroups.com... > > > Hi, > > > I am trying to use the native WinCE API WZCEnumInterfaces using > > interop in C# .NET compact framework. I have to develop this without > > the OpenNetCF wrapper. But whenever I call the function, I get the > > exception "System.NotSupportedException". I looked at the help page > > for this exception and I think I have taken care of all the possible > > causes for the exception. Could anyone please let me know anything > > that I could be doing wrong. Please find my code below: > > > [StructLayout(LayoutKind.Sequential)] > > struct INTF_KEY_ENTRY > > { > > [MarshalAs(UnmanagedType.LPWStr)] > > public string wszGuid; > > } > > > [StructLayout(LayoutKind.Sequential)] > > struct INTFS_KEY_TABLE > > { > > public uint dwNumIntfs; > > > public IntPtr pIntfs; //This is a pointer to > > INTF_KEY_ENTRY in the native c++ > > } > > > [DllImport("wzcsapi.dll", SetLastError = true)] > > private static extern ulong WZCEnumInterfaces(string pSrvAddr, > > ref INTFS_KEY_TABLE pIntfs); > > > /// <summary> > > /// find the first wireless network cards > > /// </summary> > > public void GetFirstWirelessNetworkCard() > > { > > INTFS_KEY_TABLE IntfsTable = new > > INTFS_KEY_TABLE(); > > IntfsTable.dwNumIntfs = 0; > > > IntfsTable.pIntfs = > > Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)) * > > (int)IntfsTable.dwNumIntfs); > > > ulong dwStatus = 0; > > > try > > { > > dwStatus = WZCEnumInterfaces(null , ref IntfsTable); > > } > > catch(Exception e) > > { > > int errorNum = Marshal.GetLastWin32Error(); > > > MessageBox.Show(e.Message + " Error: " + errorNum, > > "Fatal Error!"); > > return; > > } > > }
|
Pages: 1 Prev: Detect process running on PPC WM 5 Next: WCF DataContractSerializer |