注意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. Parallel线程安全问题

    废话不多说,上代码: using System; using System.Collections.Generic; using System.Threading.Tasks; namespace P ...

  2. [Swift]LeetCode226. 翻转二叉树 | Invert Binary Tree

    Invert a binary tree. Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Output: 4 / \ 7 2 / \ / \ 9 6 3 1 Tr ...

  3. [Swift]LeetCode410. 分割数组的最大值 | Split Array Largest Sum

    Given an array which consists of non-negative integers and an integer m, you can split the array int ...

  4. [Swift]LeetCode488. 祖玛游戏 | Zuma Game

    Think about Zuma Game. You have a row of balls on the table, colored red(R), yellow(Y), blue(B), gre ...

  5. [Swift]LeetCode728. 自除数 | Self Dividing Numbers

    A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is ...

  6. vue总结

    1.库和框架的区别 库:jquery 本质上就是一些列函数的集合,将一些函数封装到一个独立的就是文件中 在使用的jquery的时候,是由开发人员说了算的,也就是说开发人员起到了主导作用,而jquery ...

  7. H5 页面调试小帮手-UC 开发者工具

    调试web页面难 接触过app自动化的同学都比较清楚,如果想要对web应用或者Hybrid应用进行调试时(获取页面元素信息等等),必定绕不开的就是chrome浏览器的inspect功能了:在chrom ...

  8. 工作随笔—Java容器基础知识分享(持有对象)

    1. 概述 通常,程序总是运行时才知道的根据某些条件去创建新对象.在此之前,不会知道所需对象的数量,甚至不知道确切的类型,为解决这个普遍的编程问题:需要在任意时刻和任意位置创建任意数量的对象,所以,就 ...

  9. IntelliJ IDEA 自定义方法注解模板

    最近没啥事开始正式用Eclipse 转入 idea工具阵营,毕竟有70%的开发者在使用idea开发,所以它的魅力可想而知.刚上手大概有一天,就知道它为啥取名为 intelli(智能化)了,确实很智能, ...

  10. C# 当中 LINQ 的常规用法(Lambda 方式)

    仅以本篇博文记录 LINQ 相关操作的基本知识,原型参考自 MSDN 相关知识,中间加以自己的理解与 DEMO. 1. IEnuemrable<T>.Select() Select 方法比 ...