This appears to be incorrect, as the DNS_SERVICE_REGISTER_REQUEST pointer needs to be fixed for the lifetime of the asynchronous call (i.e. the parameter should be DNS_SERVICE_REGISTER_REQUEST*).
Also, DNS_SERVICE_REGISTER_REQUEST is generated as a managed type, so at the moment you can't store it on the heap with Marshal.AllocHGlobal either.
DnsServiceDeRegister is also affected - this should also take a pointer, not the struct directly.
Expected behavior
The first parameter to DnsServiceRegister should be a pointer, and you should be able to put the DNS_SERVICE_REGISTER_REQUEST onto the heap via Marshal.AllocHGlobal.
Actual behavior
CsWin32 generates the function signature for
DnsServiceRegister
as:This appears to be incorrect, as the
DNS_SERVICE_REGISTER_REQUEST
pointer needs to be fixed for the lifetime of the asynchronous call (i.e. the parameter should beDNS_SERVICE_REGISTER_REQUEST*
).Also,
DNS_SERVICE_REGISTER_REQUEST
is generated as a managed type, so at the moment you can't store it on the heap withMarshal.AllocHGlobal
either.DnsServiceDeRegister
is also affected - this should also take a pointer, not the struct directly.Expected behavior
The first parameter to
DnsServiceRegister
should be a pointer, and you should be able to put the DNS_SERVICE_REGISTER_REQUEST onto the heap viaMarshal.AllocHGlobal
.Repro steps
NativeMethods.txt
content:NativeMethods.json
content (if present):Any of your own code that should be shared?
This will result in an access violation when run, due to
DnsRegisterService
trying to access data on the stack that no longer exists:Context