注意NET某些类型在不同平台上的长度
NET中用句柄用得最多的是在DLLIMPORT中,混用int与intptr可能会导致某些API声明在X64平台中表现不正常,如
[DllImport("Kernel32")]
public static extern IntPtr LoadLibrary(string funcname);
[DllImport("Kernel32")]
public static extern long GetProcAddress(long handle, string funcname);
int _tmain(int argc, _TCHAR* argv[]) { int i = 0; i = sizeof(int); // x86:4 x64:4 i = sizeof(long); // x86:4 x64:4 i = sizeof(void*); // x86:4 x64:8 i = sizeof(short); // x86:2 x64:2 i = sizeof(float); // x86:4 x64:4 i = sizeof(double); // x86:8 x64:8 i = sizeof(int*); // x86:4 x64:8 i = sizeof(WORD); // x86:2 x64:2 i = sizeof(DWORD); // x86:4 x64:4 i = sizeof(LONGLONG); // x86:8 x64:8 i = sizeof(HANDLE); // x86:4 x64:8 i = sizeof(HWND); // x86:4 x64:8 i = sizeof(bool); // x86:1 x64:1 i = sizeof(char); // x86:1 x64:1 return 0; } |
参考:http://blog.csdn.net/road2010/article/details/21406639