Simple Attempt Wrapping CPP Library
- Posted by Icy_Viking Feb 28, 2023
- 1276 views
Hello all,
I am trying to wrap a CPP library, not regular C, but CPP. I am getting subscript from an atom error. I'm not suring what I am doing wrong. Is there something extra you need to do when wrapping CPP libraries?
//CPP Code
#pragma once
#ifdef GETCORETEMPINFO_EXPORTS
#define GETCORETEMPINFO_API __declspec(dllexport)
#else
#define GETCORETEMPINFO_API __declspec(dllimport)
#endif
#define UNKNOWN_EXCEPTION 0x20000000
typedef struct core_temp_shared_data
{
unsigned int uiLoad[256];
unsigned int uiTjMax[128];
unsigned int uiCoreCnt;
unsigned int uiCPUCnt;
float fTemp[256];
float fVID;
float fCPUSpeed;
float fFSBSpeed;
float fMultipier;
char sCPUName[100];
unsigned char ucFahrenheit;
unsigned char ucDeltaToTjMax;
}CORE_TEMP_SHARED_DATA,*PCORE_TEMP_SHARED_DATA,**PPCORE_TEMP_SHARED_DATA;
bool GETCORETEMPINFO_API fnGetCoreTempInfo(CORE_TEMP_SHARED_DATA *&pData);
bool WINAPI fnGetCoreTempInfoAlt(CORE_TEMP_SHARED_DATA *pData);
class GETCORETEMPINFO_API CoreTempProxy
{
public:
CoreTempProxy(void);
virtual ~CoreTempProxy(void);
UINT GetCoreLoad(int Index) const;
UINT GetTjMax(int Index) const;
UINT GetCoreCount() const;
UINT GetCPUCount() const;
float GetTemp(int Index) const;
float GetVID() const;
float GetCPUSpeed() const;
float GetFSBSpeed() const;
float GetMultiplier() const;
LPCSTR GetCPUName() const;
bool IsFahrenheit() const;
bool IsDistanceToTjMax() const;
const CORE_TEMP_SHARED_DATA &GetDataStruct() const;
bool GetData();
DWORD GetDllError() const { return GetLastError(); }
LPCWSTR GetErrorMessage();
private:
CORE_TEMP_SHARED_DATA m_pCoreTempData;
WCHAR m_ErrorMessage[100];
};
include std/machine.e include std/ffi.e atom cpu = 0 cpu = open_dll("GetCoreTempInfo.dll") if cpu = -1 then puts(1,"Failed to load DLL!\n") abort(0) end if public constant core_temp_shared_data = define_c_type({ {C_UINT,256}, --uiLoad[256] {C_UINT,128}, --uiTjMax[128] C_UINT, --iCorecnt C_UINT, --uiCPUCnt {C_FLOAT,256}, --fTemp[256] C_FLOAT, --fVID C_FLOAT, --CPUSpeed C_FLOAT, --FSBSpeed C_FLOAT, --fMultiplier {C_CHAR,100}, --CPUName[100] C_UCHAR, --uFarenheight C_UCHAR --ucDeltaToTjMax }) export constant xGetCoreLoad = define_c_func(cpu,"+GetCoreLoad",{C_INT},C_UINT), xGetTjMax = define_c_func(cpu,"+GetTjMax",{C_INT},C_UINT), xGetCoreCount = define_c_func(cpu,"+GetCoreCount",{},C_UINT), xGetCPUCount = define_c_func(cpu,"+GetCPUCount",{},C_UINT), xGetTemp = define_c_func(cpu,"+GetTemp",{C_INT},C_FLOAT), xGetCPUName = define_c_func(cpu,"+GetCPUName",{},C_WSTRING) public function GetCPUName() return c_func(xGetCPUName,{}) end function sequence n = GetCPUName() --error comes from this line printf(1,"Cores: %s",{n})

