在python中使用cppyy时,指针变量raise错误为未知类型 所以我有这个,这里是C++中的,所以我安装了CPpyy,但是当我用Python中包含CPYY的头文件时,它会引起错误 // 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);
错误在python中使用cppyy时,指针变量raise错误为未知类型 所以我有这个,这里是C++中的,所以我安装了CPpyy,但是当我用Python中包含CPYY的头文件时,它会引起错误 // 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);,python,c++,sdk,cppyy,Python,C++,Sdk,Cppyy,错误 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",
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=]
提前感谢看起来像是
SAFEARRAY
存在于oaidl.h
中,它需要在MysticLight_SDK.h
之前包含(以及在使用C++中的MysticLight_SDK.h
时通常包含的任何其他头文件)
PyPyy以预编译头的形式将标准C++标题拉入,但任何其他平台和项目头都需要显式地包含,或者需要打包成单独的字典()以允许自动加载。 更准确地说,使用上面链接的.zip文件,可以执行以下操作:
import cppyy
cppyy.include("oaidl.h") # <-- this is the one
cppyy.include("MysticLight_SDK.h")
cppyy.load_library("MysticLight_SDK_x64")
导入cppyy
cppyy.include(“oaidl.h”)#“rootcling-f myclass_rflx.cxx myclight_SDK.h”在我的命令行上执行了此操作,但在输入_line_9:27中包含的文件中得到了与上面相同的错误。/mycling_SDK.h:7:38:错误:未知类型名称“SAFEARRAY”typedefint(LPMLAPI_GetDeviceInfo)(SAFEARRAY*pDevType,SAFEARRAY**pLedCount);''' 我对这类事情还不熟悉,而你看起来像是能在这方面帮助我的人。请你好心地指导我完成这件事。谢谢你是CPPYY的作者。在你面前感到很幸运。我从没想过像你这样的大人物也会使用stackoverflow,我知道你可能没有太多的空闲时间,但我希望你能回答这个问题,所以我会给出一个更好的描述sdk文件夹有3个文件1个头文件和2个Dll文件,我想调用这些函数,获取它们将返回的值,并使用这些头文件执行一些功能一个新值。对于字典,我的意思是打包oaidl.h
,以便自动找到它。要在字典中打包MysticLight_SDK.h
,需要以与交互提示相同的方式包含oaidl.h
。我已经用一个基本的代码示例更新了上面的答案,但是我真的不知道如何使用SDK头,因为它不包含任何API,所以肯定还有其他内容。
import cppyy
cppyy.include("oaidl.h") # <-- this is the one
cppyy.include("MysticLight_SDK.h")
cppyy.load_library("MysticLight_SDK_x64")