C Class Instance from Void Pointer using Ctypes

Posted by g.d.d.c on Stack Overflow See other posts from Stack Overflow or by g.d.d.c
Published on 2013-10-15T19:07:49Z Indexed on 2013/10/17 15:56 UTC
Read the original article Hit count: 212

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about python

Related posts about c