C Class Instance from Void Pointer using Ctypes
- by g.d.d.c
I've got a C DLL that exposes a handful of methods that return void pointers to a Class like so:
void *GetLicense() {
static AppLicenseImpl ipds_;
return (void *) &ipds_;
}
In C++, after loading the DLL, I'd do this to work with it:
typedef void *(* FPGetLicense)();
GetLicense_ = (FPGetLicense)GetAddress("GetLicense");
license_ = (AppLicense *) GetLicense_();
license_->GetApplicationStatus(); // Load data so that other calls don't fail
I can't figure out how to parallel that in Python. This gets me the pointer:
d = ctypes.cdll.LoadLibrary('license.dll')
d.GetLicense.restype = ctypes.c_void_p
p = d.GetLicense() # returns ptr loc, something like 8791433660848L
But I obviously can't call p.GetApplicationStatus() in Python. Does anyone have a suggestion on how I'd instantiate that Class the rest of the way in Python so that I can call GetApplicationStatus()?