I compiled a dll for a program in Python. Here is the code of the exported function:

#include "stdafx.h" #include "PollSensors.h" #ifdef __cplusplus extern "C" { #endif __declspec( dllexport ) double __GetLightSensor(); #ifdef __cplusplus } #endif double __GetLightSensor() { Sensor sensor; if (!sensor.is_available()) { return 1; } sensor.poll(); Sleep(250); return sensor.get()[0]; } 

This is a library for receiving data from a light sensor in Windows. I think it is not necessary to give the Sensor class code, the program collected in exe works successfully and prints the data to the console. But in trouble with downloading this dll in Python:

 from ctypes import * lib = windll.LoadLibrary("lightSensor.dll") while True: print lib.__GetLightSensor() Всегда выводит только одно значение.... Несмотря на то, что данные, выводимые данной функцией меняются в зависимости от степени освещения. Что я не правильно делаю? 
  • What is it written in docs? 15.17.1.8. Returns the C int type. Attribute of the function object. - alexlz 3:07
  • Ctypes.c_double? That doesn't work either. - Xyanight 4:03

1 answer 1

Thank you, figured out.
from ctypes import *

 lib = windll.LoadLibrary("lightSensor.dll") lib.__GetLightSensor.restype = c_double while True: print c_double(lib.__GetLightSensor()) 
  • @Xyanight and what does print c_double (lib .__ GetLightSensor ()) mean possibly better print lib .__ GetLightSensor (). Value () - alexlz