So I've run into this unfortunate situation where I have to, as the title says, write a function declaration with an optional struct
parameter.
Here is the struct
:
[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES
{
public int nLength;
public IntPtr lpSecurityDescriptor;
public int bInheritHandle;
}
Here is the function in the .dll advapi.dll
:
LONG WINAPI RegSaveKey(
_In_ HKEY hKey,
_In_ LPCTSTR lpFile,
_In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes
);
Here's my declaration so far:
[DllImport("advapi32.dll", SetLastError = true)]
static extern int RegSaveKey(UInt32 hKey, string lpFile, [optional parameter here!!] );