Does inline ABI support #define func func_original?

Issue #324 resolved
justinxu
created an issue

I want to invoke a function named InternetSetOption

from cffi import FFI
ffi = FFI()
lib = ffi.dlopen('wininet.dll')
ffi.cdef('''
typedef LPVOID HINTERNET;
BOOL InternetSetOption(HINTERNET hInternet, DWORD dwOption, LPVOID lpBuffer, DWORD dwBufferLength);
''')
print type(lib.InternetSetOption)

The CFFI will return AttributeError: function/symbol 'InternetSetOption' not found in library 'wininet.dll': error 0x7f

In wininet, the head file is like:

#ifdef UNICODE
#define InternetSetOption  InternetSetOptionW
#else
#define InternetSetOption  InternetSetOptionA
#endif // !UNICODE

So I don't know how to deal with such problem. Is that a bug? Now I can only wrap InternetSetOptionW

Comments (5)

  1. justinxu reporter

    Thanks. In doc, "CFFI selects either Python or C for the module to generate based on whether the second argument to set_source() is None or not", I will try to wrap the function in API mode.

  2. justinxu reporter
    import setuptools
    from cffi import FFI
    ffibuilder = FFI()
    
    ffibuilder.set_source("_simple_example",
        r'''
        #include <windows.h>
        #include <wininet.h> 
        ''',
        libraries = ["wininet"]
    )
    ffibuilder.cdef("""
    typedef LPVOID HINTERNET;
    BOOL InternetSetOption(HINTERNET hInternet, DWORD dwOption, LPVOID lpBuffer, DWORD dwBufferLength); 
    """)
    if __name__ == "__main__":
        ffibuilder.compile(verbose=True)
        from _simple_example import lib
        print lib.InternetSetOption
    

    The API mode is awesome, if I can master the CFFI, it will be easier than ctypes.

  3. Log in to comment