WSALookupServiceBegin failing C#

  • Thread starter Gund appa via .NET 247
  • Start date
G

Gund appa via .NET 247

Hi

I am trying to run WSALookupServiceBegin from C#, here is my code extract of what I am doing

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
internal struct WSAQuerySet
{
public Int32 dwSize;
public string lpszServiceInstanceName;
public GuidlpServiceClassId;
public LPWSAVERSION lpVersion;
public string lpszComment;
public UInt32 dwNameSpace;
public Guid lpNSProviderId;
public string lpszContext;
public UInt32 dwNumberOfProtocols;
public LPAFPROTOCOLS lpafpProtocols;
public string lpszQueryString;
public UInt32 dwNumberOfCsAddrs;
public CSADDR_INFO lpcsaBuffer;
public UInt32 dwOutputFlags;
public LPBLOB lpBlob;
}

[DllImport("ws2_32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
internal static extern int WSAStartup(
[In] short wVersionRequested,
[Out] out WSAData lpWSAData
);


[DllImport("ws2_32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
internal static extern int WSALookupServiceBegin(
[MarshalAs(UnmanagedType.Struct)]
ref WSAQuerySet lpqsRestrictions,
ushort dwControlFlags,
ref Int32 lphLookup
);


int result = WSAStartup(VERSION, out d);
//it is successful


wsaq.dwNameSpace = NS_BTH;
wsaq.lpServiceClassId = GUID_BLUETOOTH_RADIO_IN_RANGE; // GUID_BLUETOOTH_L2CAP_EVENT;
wsaq.dwSize = 138; // System.Runtime.InteropServices.Marshal.SizeOf(wsaq);


int iRet = WSALookupServiceBegin( ref wsaq, dwFlags, ref hLookup);

I get this error

Attempted to read or write protected memory. This is often an indication that other memory has been corrupted.

Any help to improve this will appreciated
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top