好的,我在 .NET 4.0 中使用 C# 中的 SetFilePointer 函数。下面是我用来调用这个函数的 dllimports:
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
static extern uint SetFilePointer([In] SafeFileHandle hFile, [In] long lDistanceToMove, [Out] out int lpDistanceToMoveHigh, [In] EMoveMethod dwMoveMethod);
每当我在调试器中运行使用 SetFilePointer 函数的代码时,都会出现以下异常:
PInvokeStackImbalance was detected
Message: A call to PInvoke function 'MyDiskStuff!MyDiskStuff.HardDisk::SetFilePointer' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
每当我在调试器之外运行相同的代码时,我都不会得到上述异常。
下面是我用来调用 SetFilePointer 的代码:
public enum EMoveMethod : uint
{
Begin = 0,
Current = 1,
End = 2
}
uint retvalUint = SetFilePointer(mySafeFileHandle, myLong, out myInt, EMoveMethod.Begin);
我的 dllimport 签名有问题吗?