0

So I have this sdk and here is the documentation which is in c++ which so I installed cppyy but when I include the header file with cppyy in python it raises error

    // 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);

the errors

    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 works fine I tested it without the headers and there were no error

to code to check the implementation of this

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())

Thanks in advance

1 Answers1

1

Looks like SAFEARRAY lives in oaidl.h, which would need to be included before MysticLight_SDK.h (and any other headers that are normally be included when using MysticLight_SDK.h from C++).

cppyy pulls in the standard C++ headers in the form of a precompiled header, but any other platform and project headers need to be explicitly included, or need to be packaged into a separate dictionary (https://cppyy.readthedocs.io/en/latest/utilities.html#dictionaries) to allow automatic loading.

To be more precise, using the .zip file that you link above, the following:

import cppyy
cppyy.include("oaidl.h")                  # <-- this is the one
cppyy.include("MysticLight_SDK.h")
cppyy.load_library("MysticLight_SDK_x64")

works for me.

Beyond that, I don't know what would be the use case, because that MysticLight_SDK.h header only contains typedefs of function pointers, no actual APIs.

Wim Lavrijsen
  • 3,453
  • 1
  • 9
  • 21
  • '''rootcling -f myclass_rflx.cxx MysticLight_SDK.h''' did this on my command line but got the same error as above ''' In file included from input_line_9:27: ./MysticLight_SDK.h:7:38: error: unknown type name 'SAFEARRAY' typedef int (*LPMLAPI_GetDeviceInfo)(SAFEARRAY** pDevType, SAFEARRAY** pLedCount);''' I'm new to this kinda stuff and u look like the person who can help me akot in this. PLEASE will u be kind enough to guide me through this. Thanks – sarfaraz saleem Oct 11 '20 at 18:32
  • OOOMMMMMGGGG you are the author of CPPYY. Feeling lucky to be just in your presence. I never thought big shots like you also use stackoverflow, Would you be kind enough to guide me through this – sarfaraz saleem Oct 11 '20 at 19:23
  • I know u might not have much free time but I hope u answer to this so I'll just give a better description the sdk folder has 3 file 1 Header file and 2 Dll file and I'm interested in calling those function and getting the value they will return and executing some fuction from this header file with a new value. – sarfaraz saleem Oct 11 '20 at 19:28
  • For the dictionary, I meant packaging `oaidl.h` so that it can be automatically found. To package `MysticLight_SDK.h` in a dictionary requires including `oaidl.h` in the same manner as on the interactive prompt. I've updated the answer above with a basic code example, but I really do not see how the SDK header can be used as it doesn't contain any APIs, so there must be something more to it. – Wim Lavrijsen Oct 11 '20 at 22:54