相关疑难解决方法(0)

SetWindowLong/GetWindowLong和32位/ 64位CPU

我正在使用以下代码:

const int GWL_STYLE = (-16);

const UInt32 WS_POPUP = 0x80000000;
const UInt32 WS_CHILD = 0x40000000;

[DllImport("user32.dll", SetLastError = true)]
static extern UInt32 GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, UInt32 dwNewLong);
Run Code Online (Sandbox Code Playgroud)

在某个地方......

SetWindowLong(this.Handle, GWL_STYLE,
             ((GetWindowLong(this.Handle, GWL_STYLE) & ~(WS_POPUP)) | WS_CHILD));
Run Code Online (Sandbox Code Playgroud)

这会在32位和64位机器上正常运行吗?

如果没有,如果我编译我的应用程序作为x86进程运行,它仍然可以在64位计算机上正常工作吗?

如何在32位和64位计算机上重写以下代码?

c# 64-bit pinvoke winapi 32-bit

6
推荐指数
1
解决办法
2万
查看次数

带有非导出函数的 DllImport。为什么有效?

我刚刚在 C# 中遇到了 DllImport 的奇怪行为,我无法解释。我想知道它是如何可能的,以及我可以在哪里阅读它。案例是通过 DllImport 可以调用不真正导出表单 dll 的函数。就我而言,它是 kernel32.dll 和函数 ZeroMemory(但具有复制/移动/填充内存这样的行为)。所以,我的代码:

[DllImport("kernel32", EntryPoint = "LoadLibraryW", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr LoadLibrary(string libName);

[DllImport("kernel32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
public static extern IntPtr GetProcAddress(IntPtr module, string procName);

//WTF???
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool ZeroMemory(IntPtr address, int size);

static void TestMemory()
{
    IntPtr mem = Marshal.AllocHGlobal(100); //Allocate memory block of 100 bytes size
    Marshal.WriteByte(mem, 55);            //Write some value in …
Run Code Online (Sandbox Code Playgroud)

.net c# winapi marshalling dllimport

6
推荐指数
1
解决办法
153
查看次数

GetWindowLong与C#中的GetWindowLongPtr

我像这样使用GetWindowLong:

[DllImport("user32.dll")]
private static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);
Run Code Online (Sandbox Code Playgroud)

但根据MSDN文档,我应该使用GetWindowLongPtr与64位兼容. http://msdn.microsoft.com/en-us/library/ms633584(VS.85).aspx

GetWindowLongPtr的MSDN文档说我应该像这样定义它(在C++中):

LONG_PTR GetWindowLongPtr(HWND hWnd, int nIndex);
Run Code Online (Sandbox Code Playgroud)

我曾经使用IntPtr作为返回类型,但是我将使用什么来替代LONG_PTR?我也看到在C#中将GetWindowLong定义为:

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

什么是正确的,我如何确保正确的64位兼容性?

c# getwindowlong

3
推荐指数
2
解决办法
7250
查看次数

我不断收到“无法在DLL'user32.dll'中找到名为'GetWindowLongPtrA'的入口点”

我正在尝试使用,GetWindowLongPtrA但我一直收到“无法在DLL'user32.dll'中找到名为'GetWindowLongPtrA'的入口点”。(也会SetWindowLongPtrA出现相同的错误)。我已经尝试了许多在Google上找到的解决方案,但是他们没有解决。

这是我编写的函数的声明:

[DllImport("user32.dll")]
public static extern IntPtr GetWindowLongPtrA(IntPtr hWnd, int nIndex);
Run Code Online (Sandbox Code Playgroud)

尝试将put EntryPoint = "GetWindowLongPtrA",更改GetWindowLongPtrAGetWindowLongPtr,put CharSet = CharSet.Ansi,切换为GetWindowLongPtrWwith CharSet = CharSet.Unicode等,它们都不起作用。

我的计算机正好是“ 64位”(但是不能调用该64位WinAPI函数吗?)。操作系统是Windows 10。

[1]:https://i.stack.imgur.com/3JrGw.png

但是我的系统驱动器的可用空间不足。这可能是原因吗? 在此处输入图片说明

这个问题有什么解决方案?

.net c# pinvoke winapi getwindowlong

2
推荐指数
1
解决办法
518
查看次数

标签 统计

c# ×4

winapi ×3

.net ×2

getwindowlong ×2

pinvoke ×2

32-bit ×1

64-bit ×1

dllimport ×1

marshalling ×1