Skip to content

Foreign library with cdll instead of windll #77

@aquilesC

Description

@aquilesC

I'm building a wrapper for the new Thorlabs Kinesis drivers using from lantz.foreign import LibraryDriver, and found that by default the class Library loads the dll as:

if os.name == 'nt':
    library = ctypes.WinDLL(library)

However, for some reason when I try to call a function, like CC_Open (this is device specific), I get the following error:

Exception: While calling CC_Open with [b'83843619'] (was (b'83843619',)): Procedure probably called with too many arguments (4 bytes in excess)

This is easily solved if i use library = ctypes.CDLL(library).

I imagine that it is not safe to assume the library loader based solely on the operating system, however I don't see a clear way of overriding it; the class Library is able to do so:

class Library(object):
    def __init__(self, library, prefix='', wrapper=None):
        if isinstance(library, str):

just by providing a library that is not a string (i.e. the library already loaded)
But the base class LibraryDriver iterates over names. I don't see a clear solution that wouldn't ruin downstream code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions