iohidmanageropen返回错误代码-536870201
我在Mac上的应用程序中使用USB的新手。当我记录iohidmanageropen(x,y)函数的结果时,请致电我的应用程序,我将获得错误代码-536870201。我在以下帖子中发现()-536870207被转化为kioreturnnotprivileged。如何翻译错误代码并了解错误的原因?
我正在运行的代码:
manager = std::make_unique<CoreFoundationReference<IOHIDManagerRef>>(
IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone));
IOHIDManagerSetDeviceMatching(manager->Get(), nullptr);
IOHIDManagerRegisterDeviceMatchingCallback(
manager->Get(), &MacHidDeviceManager::OnDeviceMatched, this);
IOHIDManagerRegisterDeviceRemovalCallback(
manager->Get(), &MacHidDeviceManager::OnDeviceRemoved, this);
IOHIDManagerScheduleWithRunLoop(
manager->Get(), CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
auto ioResult = IOHIDManagerOpen(manager->Get(), kIOHIDOptionsTypeNone);
if (ioResult != kIOReturnSuccess) {
throw UsbInterfaceException("DeviceManager::DeviceManager", "Cannot open IO device manager, error: {}", ioResult);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于iokit返回值(
ioreturn
),将它们打印成十六进制,(“ 0x%x”)通常更有帮助,因为这是在
< /a>。因此,例如,在十六进制中以
0xe00002c7
表示-536870201。0xe0000000
部分表示它是一个iokit常数,2C7
将其标识为kioreturnunsununsununsupported
您尚未发布任何有关该升级或参数的代码或其他详细信息,请访问您的iohidmanageropen()
呼叫,所以我不能真正说出为什么它应该返回kioreturnunsunsupported < /code>没有更多详细信息。
基于您添加到问题中的代码,我尝试提出最小可重复的示例:
最初失败(
0xe0000002e2
/code>)由于没有安全&amp;隐私,但是一旦我授予系统偏好的许可,就可以成功。我已经在MacOS 11和13上对此进行了测试,结果相同。我怀疑您尚未发布的一些代码(corefoundationReference
?)可能是问题所在。还是一些沙箱问题?顺便说一句,我维护着一个小型iokit助手实用程序库,其中之一是函数
djt_ioreturn_string
将ioreturn
值转换为这些常数的字符串表示。 (您只需要在项目中包含ioreturn_strings.cpp和ioreturn_strings.h文件,ioreturn_strings.h可以是#include
/#import
#import ed pure c或objective -c,只有.cpp使用C ++。)For IOKit return values (
IOReturn
) it's typically much more helpful to print them as hexadecimal, ("0x%x") as that's how the constants are defined in<IOKit/IOReturn.h>
.So for example, -536870201 is represented in hexadecimal as
0xE00002C7
. The0xE0000000
part means it's an IOKit constant, the last few digits of2C7
identify it askIOReturnUnsupported
.You haven't posted any code or other details about the run-up or arguments to yourIOHIDManagerOpen()
call, so I can't really say why it should returnkIOReturnUnsupported
without more details.Based on the code you added to your question, I tried to come up with the minimum reproducible sample:
This initially fails (
0xe00002e2
,kIOReturnNotPermitted
) due to missing consent from Security & Privacy, but succeeds once I've granted that permission in System Preferences. I've tested this on macOS 11 and 13 with the same result. I suspect some of the code you haven't posted (CoreFoundationReference
?) might be where the problem lies. Or perhaps some sandboxing issue?Incidentally, I maintain a small library of IOKit helper utilities, and one of those things is a function
djt_ioreturn_string
which convertsIOReturn
values into string representations of those constants. (You just need to include the ioreturn_strings.cpp and ioreturn_strings.h files in your project, the ioreturn_strings.h can be#include
/#import
ed from pure C or Objective-C, just the .cpp uses C++.)