使用平台调用时,将参数指定为[In]
是否会影响运行时处理这些参数的方式?
例如,当 PInvoking 时CreateRemoteThread
,根据 MSDN 上的文章lpThreadId
指定:out
HANDLE WINAPI CreateRemoteThread(
_In_ HANDLE hProcess,
_In_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_ SIZE_T dwStackSize,
_In_ LPTHREAD_START_ROUTINE lpStartAddress,
_In_ LPVOID lpParameter,
_In_ DWORD dwCreationFlags,
_Out_ LPDWORD lpThreadId
);
所有其他论点都是_In_
. 在我的 C# 代码中,我像这样处理该特定函数:
[DllImport("kernel32.dll", EntryPoint = "CreateRemoteThread", SetLastError = true)]
public static extern IntPtr CreateRemoteThread(
IntPtr hProcess,
IntPtr lpThreadAttributes,
uint dwStackSize,
IntPtr lpStartAddress,
IntPtr lpParameter,
uint dwCreationFlags,
[Out] IntPtr lpThreadId);
将[Out]
属性添加到lpThreadId
以便运行时知道将其编组回调用者。如果我将函数签名更改为此,运行时处理我的函数是否会有所不同:
[DllImport("kernel32.dll", EntryPoint = "CreateRemoteThread", SetLastError = true)]
public static extern IntPtr CreateRemoteThread(
[In] IntPtr hProcess,
[In] IntPtr lpThreadAttributes,
[In] uint dwStackSize,
[In] IntPtr lpStartAddress,
[In] IntPtr lpParameter,
[In] uint dwCreationFlags,
[Out] IntPtr lpThreadId);
或者它会是完全相同的东西吗?[In]
默认情况下是否考虑参数?