Convert a .lib and .h file to a DLL that can be used in Python
<p>So I'm trying to import some function contained in a .lib file into Python to build an SDK that will allow me to talk to some special hardware components.  I read online that it is not really easy to import a .lib file into Python:</p>

<p><a href="https://stackoverflow.com/questions/3668373/static-library-lib-to-python-project">Static library (.lib) to Python project</a></p>

<p>So I'm trying to build a dll using the .lib and its corresponding .h file.  I don't have access to the .lib source code.  All I have access to is the .h file.  I've looked online and found this:</p>

<p><a href="https://stackoverflow.com/questions/2384932/converting-static-link-library-to-dynamic-dll">Converting static link library to dynamic dll</a> </p>

<p>Since I'm building the DLL for Python I can't use the .def file.  I tried directly just importing the .h and .lib file into a project and creating a dll file but the functions were not implemented.  So I tried making a separate .h file called wrapper that wraps around the functions in the .h file and calls them, but the functions are still not implemented and working.  And honestly I highly doubt what I did is correct  </p>

<p>Here is my code:</p>

<p>hardware.h - the header file that came with the .lib file (note only putting up one function)</p>

<pre><code>extern "C" int WINAPI GetDigitalOutputInfo(unsigned int deviceNumbers[16], 
                                            unsigned int numBits[16], 
                                            unsigned int numLines[16]);
</code></pre>

<p>_hardware.h - wrapper around the original header file</p>

<pre><code>#pragma once

#include &lt;Windows.h&gt;

#ifdef Hardware_EXPORTS
#define Hardware_API __declspec(dllexport) 
#else
#define Hardware_API __declspec(dllimport) 
#endif

namespace Hardware
{
    class Functions
    {
        public:
            static Hardware_API int NewGetDigitalOutputInfo(unsigned int deviceNumbers[16], unsigned int numBits[16], unsigned int numLines[16]);
    };

}
</code></pre>

<p>Hardware.cpp - implementing the wrapper</p>

<pre><code>#include "stdafx.h"
#include "hardware.h"
#include "_hardware.h"
#pragma comment(lib, "..\\lib\\PlexDO.lib")
#pragma comment(lib, "legacy_stdio_definitions.lib")

namespace Hardware
{
    int Functions::NewGetDigitalOutputInfo(unsigned int deviceNumbers[16], unsigned int numBits[16], unsigned int numLines[16]) {
        return GetDigitalOutputInfo(deviceNumbers, numBits, numLines);
    }
}
</code></pre>

<p>Anyway I feel like making a wrapper is pointless as I should be able to just use the original .h file and .lib file directly to call the functions. Unless making a wrapper is the only way I can make a dll without getting the lib file source code.  Are there ways to make a dll without knowing the lib file source code?  Is there a way to import the lib file directly into Python?  Any help is appreciated.  </p>