首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在python中使用cppyy时,指针变量将错误提升为未知类型

在python中使用cppyy时,指针变量将错误提升为未知类型
EN

Stack Overflow用户
提问于 2020-10-11 21:12:49
回答 1查看 119关注 0票数 0

我有这个sdk,这是documentation,它在c++中,所以我安装了cppyy,但是当我在python中包含带有cppyy的头文件时,它会引发错误。

代码语言:javascript
运行
复制
    // MysticLight_SDK.h : header file
//

#pragma once

typedef int (*LPMLAPI_Initialize)();
typedef int (*LPMLAPI_GetDeviceInfo)(SAFEARRAY** pDevType, SAFEARRAY** pLedCount);
typedef int (*LPMLAPI_GetDeviceName)(BSTR type, SAFEARRAY** pDevName);
typedef int (*LPMLAPI_GetDeviceNameEx)(BSTR type, DWORD index, BSTR* pDevName);
typedef int (*LPMLAPI_GetErrorMessage)(int ErrorCode, BSTR* pDesc);
typedef int (*LPMLAPI_GetLedName)(BSTR type, SAFEARRAY** pLedName);
typedef int (*LPMLAPI_GetLedInfo)(BSTR type, DWORD index, BSTR* pName, SAFEARRAY** pLedStyles);
typedef int (*LPMLAPI_GetLedColor)(BSTR type, DWORD index, DWORD* R, DWORD* G, DWORD* B);
typedef int (*LPMLAPI_GetLedStyle)(BSTR type, DWORD index, BSTR* style);
typedef int (*LPMLAPI_GetLedMaxBright)(BSTR type, DWORD index, DWORD* maxLevel);
typedef int (*LPMLAPI_GetLedBright)(BSTR type, DWORD index, DWORD* currentLevel);
typedef int (*LPMLAPI_GetLedMaxSpeed)(BSTR type, DWORD index, DWORD* maxLevel);
typedef int (*LPMLAPI_GetLedSpeed)(BSTR type, DWORD index, DWORD* currentLevel);
typedef int (*LPMLAPI_SetLedColor)(BSTR type, DWORD index, DWORD R, DWORD G, DWORD B);
typedef int (*LPMLAPI_SetLedColors)(BSTR type, DWORD AreaIndex, SAFEARRAY** pLedName, DWORD* R, DWORD* G, DWORD* B);
typedef int (*LPMLAPI_SetLedColorEx)(BSTR type, DWORD AreaIndex, BSTR pLedName, DWORD R, DWORD G, DWORD B, DWORD );
typedef int (*LPMLAPI_SetLedColorSync)(BSTR type, DWORD AreaIndex, BSTR pLedName, DWORD R, DWORD G, DWORD B, DWORD );
typedef int (*LPMLAPI_SetLedStyle)(BSTR type, DWORD index, BSTR style);
typedef int (*LPMLAPI_SetLedBright)(BSTR type, DWORD index, DWORD level);
typedef int (*LPMLAPI_SetLedSpeed)(BSTR type, DWORD index, DWORD level);

错误

代码语言:javascript
运行
复制
    Traceback (most recent call last):
  File ".\check.py", line 5, in <module>
    cppyy.include('MysticLight_SDK.h')
  File "C:\Users\sarfaraz\AppData\Local\Programs\Python\Python37\lib\site-packages\cppyy\__init__.py", line 217, in include
    raise ImportError('Failed to load header file "%s"%s' % (header, err.err))
ImportError: Failed to load header file "MysticLight_SDK.h"
In file included from input_line_18:1:
./MysticLight_SDK.h:7:38: error: unknown type name 'SAFEARRAY'
typedef int (*LPMLAPI_GetDeviceInfo)(SAFEARRAY** pDevType, SAFEARRAY** pLedCount);
                                     ^
./MysticLight_SDK.h:7:60: error: unknown type name 'SAFEARRAY'
typedef int (*LPMLAPI_GetDeviceInfo)(SAFEARRAY** pDevType, SAFEARRAY** pLedCount);
                                                           ^
./MysticLight_SDK.h:8:38: error: unknown type name 'BSTR'
typedef int (*LPMLAPI_GetDeviceName)(BSTR type, SAFEARRAY** pDevName);
                                     ^
./MysticLight_SDK.h:8:49: error: unknown type name 'SAFEARRAY'
typedef int (*LPMLAPI_GetDeviceName)(BSTR type, SAFEARRAY** pDevName);
                                                ^
./MysticLight_SDK.h:9:40: error: unknown type name 'BSTR'
typedef int (*LPMLAPI_GetDeviceNameEx)(BSTR type, DWORD index, BSTR* pDevName);
                                       ^
./MysticLight_SDK.h:9:64: error: unknown type name 'BSTR'
typedef int (*LPMLAPI_GetDeviceNameEx)(BSTR type, DWORD index, BSTR* pDevName);
                                                               ^
./MysticLight_SDK.h:10:55: error: unknown type name 'BSTR'
typedef int (*LPMLAPI_GetErrorMessage)(int ErrorCode, BSTR* pDesc);
                                                      ^
./MysticLight_SDK.h:11:35: error: unknown type name 'BSTR'
typedef int (*LPMLAPI_GetLedName)(BSTR type, SAFEARRAY** pLedName);
                                  ^
./MysticLight_SDK.h:11:46: error: unknown type name 'SAFEARRAY'
typedef int (*LPMLAPI_GetLedName)(BSTR type, SAFEARRAY** pLedName);
                                             ^
./MysticLight_SDK.h:12:35: error: unknown type name 'BSTR'
typedef int (*LPMLAPI_GetLedInfo)(BSTR type, DWORD index, BSTR* pName, SAFEARRAY** pLedStyles);
                                  ^
./MysticLight_SDK.h:12:59: error: unknown type name 'BSTR'
typedef int (*LPMLAPI_GetLedInfo)(BSTR type, DWORD index, BSTR* pName, SAFEARRAY** pLedStyles);
                                                          ^
./MysticLight_SDK.h:12:72: error: unknown type name 'SAFEARRAY'
typedef int (*LPMLAPI_GetLedInfo)(BSTR type, DWORD index, BSTR* pName, SAFEARRAY** pLedStyles);
                                                                       ^
./MysticLight_SDK.h:13:36: error: unknown type name 'BSTR'
typedef int (*LPMLAPI_GetLedColor)(BSTR type, DWORD index, DWORD* R, DWORD* G, DWORD* B);
                                   ^
./MysticLight_SDK.h:14:36: error: unknown type name 'BSTR'
typedef int (*LPMLAPI_GetLedStyle)(BSTR type, DWORD index, BSTR* style);
                                   ^
./MysticLight_SDK.h:14:60: error: unknown type name 'BSTR'
typedef int (*LPMLAPI_GetLedStyle)(BSTR type, DWORD index, BSTR* style);
                                                           ^
./MysticLight_SDK.h:15:40: error: unknown type name 'BSTR'
typedef int (*LPMLAPI_GetLedMaxBright)(BSTR type, DWORD index, DWORD* maxLevel);
                                       ^
./MysticLight_SDK.h:16:37: error: unknown type name 'BSTR'
typedef int (*LPMLAPI_GetLedBright)(BSTR type, DWORD index, DWORD* currentLevel);
                                    ^
./MysticLight_SDK.h:17:39: error: unknown type name 'BSTR'
typedef int (*LPMLAPI_GetLedMaxSpeed)(BSTR type, DWORD index, DWORD* maxLevel);
                                      ^
./MysticLight_SDK.h:18:36: error: unknown type name 'BSTR'
typedef int (*LPMLAPI_GetLedSpeed)(BSTR type, DWORD index, DWORD* currentLevel);
                                   ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]

cppyy运行得很好,我在没有标题的情况下对它进行了测试,没有出现错误

要编写代码以检查此

代码语言:javascript
运行
复制
import cppyy
cppyy.include('MysticLight_SDK.h')

cppyy.cppdef("""
int main() {
    int c;
    int a = 10;
    int b = 10;
    c = a+b;
    return c;
    
};""")

c = cppyy.gbl.main

print(c())

提前感谢

EN

Stack Overflow用户

回答已采纳

发布于 2020-10-12 01:40:09

看起来SAFEARRAY位于oaidl.h中,它需要包含在MysticLight_SDK.h之前(以及在C++中使用MysticLight_SDK.h时通常包含的任何其他标头)。

https://cppyy.readthedocs.io/en/latest/utilities.html#dictionaries以预编译头的形式拉入标准的C++头,但任何其他平台和项目头都需要显式包含,或者需要打包到单独的字典( cppyy )中以允许自动加载。

更准确地说,使用上面链接的.zip文件,如下所示:

代码语言:javascript
运行
复制
import cppyy
cppyy.include("oaidl.h")                  # <-- this is the one
cppyy.include("MysticLight_SDK.h")
cppyy.load_library("MysticLight_SDK_x64")

这对我很有效。

除此之外,我不知道用例是什么,因为MysticLight_SDK.h头只包含函数指针的typedefs,没有实际的API。

票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64304401

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档