Hey all
Just have a question regarding bluetooth setup in C#, I need to call the following function and so created the corresponding template:
and to be able to supply the LPWSAQUERYSET parameter I created the following struct:Code:INT WSALookupServiceBegin( __in LPWSAQUERYSET lpqsRestrictions, __in DWORD dwControlFlags, __out LPHANDLE lphLookup ); [DllImport(WINSOCK_DLL, CharSet = CharSet.Auto, SetLastError=true)] public static extern int WSALookupServiceBegin(WSAQUERYSET querySet, int flags, ref int lookupHandle);
using this I run the following code:Code:struct WSAQUERYSET { public Int32 dwSize; public String szServiceInstanceName; public IntPtr lpServiceClassId; public IntPtr lpVersion; public String lpszComment; public Int32 dwNameSpace; public IntPtr lpNSProviderId; public String lpszContext; public Int32 dwNumberOfProtocols; public IntPtr lpafpProtocols; public String lpszQueryString; public Int32 dwNumberOfCsAddrs; public IntPtr lpcsaBuffer; public Int32 dwOutputFlags; public IntPtr Blob; }
As mentioned in the code I get a NotSupportedException when callling the WSALookupServiceBegin method which I suspect is due to the strings in the struct I created (as it disappears when I remove them but gives a different problem). How is my definition of WSAQUERYSET not correct?Code:/// <summary> /// Search for devices in the area /// </summary> public void scan() { int LUP_CONTAINERS = 16; //get version 2.2 ushort version = 0; version = 2 << 7; version += 2; byte [] data = new byte [15]; int result = SafeNativeMethods.WSAStartup(version, data); // returns 0 int param = 0; WSAQUERYSET q = new WSAQUERYSET(); int iRet = SafeNativeMethods.WSALookupServiceBegin(q,LUP_CONTAINERS,ref param); // NOT SUPPORTED EXCEPTION int last_error = SafeNativeMethods.WSAGetLastError(); // do other stuff.... }


Reply With Quote