gpt4 book ai didi

c# - 从 C++ 到 C# 的 bool 指针

转载 作者:太空狗 更新时间:2023-10-29 20:28:35 34 4
gpt4 key购买 nike

我想在我的 C# 应用程序中使用 DLLImport 使用 C++ DLL 中的函数:

BOOL IsEmpty( DWORD KeyID, BOOL *pFlag )

我尝试了很多组合但都是徒劳的,例如:

public extern static bool IsEmpty(int KeyID, ref bool pFlag);

该方法返回 false(这意味着错误)。

知道怎么做吗?

最佳答案

收件人quote "Willy" (有修正案):

Beware the booleans!

Win32 defines different versions of booleans.

1) BOOL used by most Win32 API's, is an unsigned int a signed int (4 bytes)

2) BOOLEAN is a single byte, only used by a few win32 API's!!

3) and C/C++ has it's builtin 'bool' which is a single byte

...并添加@tenfour 指出的内容:

4) the even more bizarre VARIANT_BOOL

typedef short VARIANT_BOOL;
#define VARIANT_TRUE ((VARIANT_BOOL)-1)
#define VARIANT_FALSE ((VARIANT_BOOL)0)

对于 BOOL,有符号或无符号的性质应该无关紧要,因为唯一的“假”模式是 0。因此请尝试将其视为 4 字节的数量...但是您与 DWORD 接口(interface) may be satisfactory ,(我没有处理 Windows 64 位约定。)

关于c# - 从 C++ 到 C# 的 bool 指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12711324/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com