注意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

 

 

混用Int与IntPtr导致GetProcAddress始终返回null的更多相关文章

  1. Android fragment-findFragmentByTag 始终返回 null

    我曾四处看看,在我的案子中找到几个与类似的主题,但没有帮助的问题.我想访问现有活动片段使用getSupportFragmentManager().findFragmentByTag(TAG),但它始终 ...

  2. Unity 使用 Stripping Level == Use micro mscorlib 导致 MD5.Create() 返回NULL

    这几天在弄资源更新,昨天导出Android APK 到手机上測试,发现MD5 校验的时候一直出错.打出Log 又一次导包測试发现 MD5.Create() 返回NULL 可是在电脑上是好好的,在手机上 ...

  3. 注册表键值明明存在OpenSubKey始终返回null,解决方案

    先上代码及实例 RegistryKey rsg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Macromedia\FlashPaper Pri ...

  4. Android 成功 使用GPS获取当前地理位置(解决getLastKnownLocation 返回 null)

    最近遇到一个比较棘手的问题:使用GPS定位无法获取当前的地理位置,即getLastKnownLocation方法始终返回null.   后来一篇博文 getLastKnownLocation()返回n ...

  5. fopen() 返回 NULL, 奇葩原因:当前进程打开多个句柄,忘记关闭。(bug)

    今天在测试一个程序的时候,突然第一次弹出错误对话框,提示: 创建新文件失败. fopen() 返回 NULL 我又重启程序测试,还是提示同样的错误. 经过几分钟的检查,发现一个规律:当处理到500多个 ...

  6. 解决InetAddress.isReachable(timeout)在windows xp始终返回false的bug

    笔者最近在做产品,其中一个环节用到ping测试主机是否在线. 开发环境:Windows 7 64bit+JDK1.8 x64 以下是检测主机是否在线,开发环境中测试通过 public static b ...

  7. C++ 动态加载 DLL 时,GetProcAddress() 返回 NULL,GetLastError() 获取错误代码为 127

    1.问题现象: 采用“运行期间动态链接”自己的 dll 文件,LoadLibrary() 成功获取 dll 模块句柄,但是 GetProcAddress() 返回 NULL. 2.问题分析: 调用 G ...

  8. [转载]C#中int和IntPtr相互转换

    方法一. int转IntPtr int i = 12;           IntPtr p = new IntPtr(i); IntPtr转int int myi = (int)p;         ...

  9. charles功能(三)弱网测试(模拟超慢网速,会导致接口数据返回超时的那种慢)

    模拟超慢网速(会导致接口数据返回超时的那种...) 设置带宽和延迟时间(毫秒) 注:可以根据下图中的翻译体会下导致网络延迟的原因: 然后打开网页回变得非常满

随机推荐

  1. 【RL-TCPnet网络教程】第9章 RL-TCPnet网络协议栈移植(uCOS-III)

    第9章        RL-TCPnet网络协议栈移植(uCOS-III) 本章教程为大家讲解RL-TCPnet网络协议栈的uCOS-III操作系统移植方式,学习了第6章讲解的底层驱动接口函数之后,移 ...

  2. Python 爬虫入门(一)——爬取糗百

    爬取糗百内容 GitHub 代码地址https://github.com/injetlee/Python/blob/master/qiubai_crawer.py 微信公众号:[智能制造专栏],欢迎关 ...

  3. [Swift]LeetCode66. 加一 | Plus One

    Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The ...

  4. [Swift]LeetCode218. 天际线问题 | The Skyline Problem

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  5. [Swift]LeetCode331. 验证二叉树的前序序列化 | Verify Preorder Serialization of a Binary Tree

    One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, ...

  6. [Swift]LeetCode498. 对角线遍历 | Diagonal Traverse

    Given a matrix of M x N elements (M rows, N columns), return all elements of the matrix in diagonal ...

  7. [Swift]LeetCode719. 找出第 k 小的距离对 | Find K-th Smallest Pair Distance

    Given an integer array, return the k-th smallest distance among all the pairs. The distance of a pai ...

  8. [Swift]LeetCode736. Lisp 语法解析 | Parse Lisp Expression

    You are given a string expressionrepresenting a Lisp-like expression to return the integer value of. ...

  9. Primitive Assembly

    I found something in the Specification of OpenGL Version 4.6 (Core Profile): The output of Vertex Sh ...

  10. Ceres配置(vs2013+Win10)

    主要参考文:Ceres Solver 在Windows下安装配置笔记 eigen.gflags.glog.suitesparse按照上面的链接中的指导配置即可. 配置ceres的时候,按照上面的链接内 ...