For a function marshalled like that:
/*************************************************
* DWORD WINAPI WlanHostedNetworkSetProperty(
* _In_ HANDLE hClientHandle,
* _In_ _WLAN_HOSTED_NETWORK_OPCODE OpCode,
* _In_ DWORD dwDataSize,
* _In_ PVOID pvData,
* _Out_opt_ P_WLAN_HOSTED_NETWORK_REASON pFailReason,
* _Reserved_ PVOID pvReserved
* );
*************************************************/
[DllImport("Wlanapi.dll", SetLastError = true)]
public static extern UInt32 WlanHostedNetworkSetProperty(
[In] IntPtr hClientHandle,
[In] _WLAN_HOSTED_NETWORK_OPCODE OpCode,
[In] UInt32 dwDataSize,
[In] IntPtr pvData,
[Out] out _WLAN_HOSTED_NETWORK_REASON pFailReason,
[In, Out] IntPtr pvReserved
);
Microsoft documentation says that when I pass
_WLAN_HOSTED_NETWORK_OPCODE._WLAN_HOSTED_NETWORK_OPCODE_enable
as a parameter of OpCode, the value of pvData should be a pointer to a Boolean value.
Hereis the documentation for that function
I have no idea though how to get an IntPtr to point to a Boolean?
Should it be done in a similar way to when I pass a pointer to a struct as pvData :
int size = Marshal.SizeOf(settings); //*settings* is a struct with some data
IntPtr pSettings = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(settings, pSettings, true);
/* use the IntPtr */
Marshal.FreeHGlobal(pSettings);
But instead I marshal the Boolean? Or is there an easier way?
Thanks for your help all lovely people.
Win32 BOOL is DWORD. You can define pvData as
ref UInt32orref Int32for this case. Or leave pvData as IntPtr, allocate unmanaged memory withMarshal.AllocHGLobal(Marshal.SizeOf(Int32)), and fill this memory withMarshal.WriteInt32.