在C#中GetWindowLong VS GetWindowLongPtr [英] GetWindowLong vs GetWindowLongPtr in C#

查看:2613
本文介绍了在C#中GetWindowLong VS GetWindowLongPtr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用GetWindowLong是这样的:

I was using GetWindowLong like this:

[DllImport("user32.dll")]
private static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);



但根据MSDN文档我应该使用GetWindowLongPtr将64位兼容。
http://msdn.microsoft.com/ EN-US /库/ ms633584(VS.85)的.aspx

MSDN文档为GetWindowLongPtr说,我应该定义它像这样(在C ++)

The MSDN docs for GetWindowLongPtr say that I should define it like this (in C++):

LONG_PTR GetWindowLongPtr(HWND hWnd, int nIndex);



我以前使用的IntPtr作为返回类型,但赫克我会用一个相当于什么对于LONG_PTR?我还看到GetWindowLong在C#中定义的:

I used to be using IntPtr as the return type, but what the heck would I use for an equivalent for LONG_PTR? I have also seen GetWindowLong defined as this in C#:

[DllImport("user32.dll")]
private static extern long GetWindowLong(IntPtr hWnd, int nIndex);



什么是正确的,我怎么能保证适当的64位兼容性如何?

What is right, and how can I ensure proper 64bit compatibility?

推荐答案

可惜这不是那么容易,因为GetWindowLongPtr不32位的Windows存在。在32位系统GetWindowLongPtr只是一个C宏指向GetWindowLong。如果你真的需要使用GetWindowLongPtr在32位和64位系统,你必须确定一个正确的在运行时调用。参见 pinvoke.net

Unfortunately it's not that easy, because GetWindowLongPtr doesn't exist in 32bit Windows. On 32bit systems GetWindowLongPtr is just a C macro that points to GetWindowLong. If you really need to use GetWindowLongPtr on both 32 and 64 bit systems you'll have to determine the correct one to call at run time. See the description at pinvoke.net

这篇关于在C#中GetWindowLong VS GetWindowLongPtr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆