<分区>
所以我遇到了这种不幸的情况,正如标题所说,我必须编写一个带有可选 struct
参数的函数声明。
这是结构
:
[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES
{
public int nLength;
public IntPtr lpSecurityDescriptor;
public int bInheritHandle;
}
这是 .dll 中的函数 advapi.dll
:
LONG WINAPI RegSaveKey(
_In_ HKEY hKey,
_In_ LPCTSTR lpFile,
_In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes
);
到目前为止,这是我的声明:
[DllImport("advapi32.dll", SetLastError = true)]
static extern int RegSaveKey(UInt32 hKey, string lpFile, [optional parameter here!!] );