Skip to content

How to call a method which expects a pointer? #250

Answered by AArnott
stiezinger asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for reaching out. This is a sub-par experience and I filed microsoft/win32metadata#452 to get this fixed in the metadata. The only real problem is the EnumInfo parameter should be out instead of ref. So just set it to null.

In the meantime, this syntax should work. You don't want to use Marshal.PtrToStructure probably because you need the original pointer to release the memory, and honestly the syntax doesn't get any easier anyway.

using System;
using Microsoft.Windows.Sdk;

unsafe
{
    uint resumeHandle = 0;
    uint preferredMaximum = 65536;
    DHCP_IP_ARRAY* enumInfo = null;
    while (PInvoke.DhcpEnumSubnets("192.168.1.1",
        ref resumeHandle,
        preferredMaximum,

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@stiezinger
Comment options

@AArnott
Comment options

@stiezinger
Comment options

@AArnott
Comment options

@stiezinger
Comment options

Answer selected by stiezinger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants