CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2007
    Posts
    18

    Bluetooth Initialization query

    Hey all

    Just have a question regarding bluetooth setup in C#, I need to call the following function and so created the corresponding template:

    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);
    and to be able to supply the LPWSAQUERYSET parameter I created the following struct:

    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;
        }
    using this I run the following code:

    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....
    
            }
    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?

  2. #2
    Join Date
    Jan 2007
    Posts
    18

    Re: Bluetooth Initialization query

    actually if any mods wanna move this to the C# forum...

  3. #3
    Join Date
    Aug 2010
    Posts
    51

    Re: Bluetooth Initialization query

    hi,

    Ihave a question regarding bluetooth setup in C#, I need to call the following function and so created the corresponding template. pl. send a nice message.


    thanks for message



    regards,
    phe9oxis,
    http://www.guidebuddha.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured