我有一个正在进行的项目,需要使用Topaz Signature Capture垫。我们的产品当前使用Topaz提供的ActiveX控件来收集网站上的签名,但是我们正在尝试移至由Python驱动的桌面应用程序。 Python将使我们无需太多额外工作即可扩展到多个操作系统。

Topaz提供了一个“C”库(http://www.topazsystems.com/sigpluslibrary.html)以与其设备接口(interface)。我相信我已经确定它实际上是C++(使用类和其他C++构造)。我曾尝试使用SWIG和Cython为Python创建包装器,但运气并不好。

我的SWIG目录结构是这样的:

  • SigSwig
  • 包括(包含来自Topaz共享C库的所有头文件)
  • setup.py
  • SigLib.i
  • Signature.i
  • 等...

  • Setup.py

    # setup.py
    import distutils
    from distutils.core import setup, Extension
    
    module = Extension(
                            "_SigLib",
                            ["SigLib.i"],
                            swig_opts=['-c++'],
                            language='c++',
                            library_dirs=['c:\Python27'],
                            libraries=["SigLib", "hid", "LibJpeg", "libtiff", "WINTAB32", "WNTAB32X", "zlib"],
                            extra_options=["SigLib.lib", "hid.lib", "LibJpeg.lib", "libtiff.lib", "WINTAB32.LIB", "WNTAB32X.LIB", "zlib.lib"]
                        )
    
    setup(
          name = "Signature Capture",
          version = "1.0",
          ext_modules = [module]
    )
    

    SigLib.i

    %module SigLib
    %{
    #define SIGAPI
    #include "Include\SigLib.h"
    %}
    
    %include TabletParameters.i
    %include TabletInterface.i
    %include LCDInterface.i
    %include Signature.i
    

    签名

    %module Signature
    %include "Include\Signature.h"
    

    我很难理解SWIG示例,但是据我所知这应该没问题。 SigLib.i加载到主 header (SigLib.h)中,该 header 包含SIGAPI的声明以及所有主要的include文件。它不包括Signature.h(或其他接口(interface)文件中的任何其他头文件),因为它不跟随所有头文件。然后它将加载其他接口(interface)文件。 Signature.i和所有其他接口(interface)文件仅包含对要解析的 header 的引用。

    我尝试了几种不同的方法,这似乎是迄今为止最好的方法。但是,当我执行setup.py时,出现以下错误:
    SigLib_wrap.cpp(3417) : error C2065: 'temp' : undeclared identifier
    SigLib_wrap.cpp(3418) : error C2065: 'temp' : undeclared identifier
    SigLib_wrap.cpp(3418) : error C2059: syntax error : '*'
    SigLib_wrap.cpp(3419) : error C2513: 'TabletParameters' : no variable declared before '='
    SigLib_wrap.cpp(3419) : error C2065: 'temp' : undeclared identifier
    SigLib_wrap.cpp(3420) : error C2065: 'temp' : undeclared identifier
    SigLib_wrap.cpp(3420) : error C2541: 'delete' : cannot delete objects that are not pointers
    SigLib_wrap.cpp(3432) : error C2275: 'TabletParameters' : illegal use of this type as an expression c:\users\kevin\downloads\sigpython\include\TabletParameters.h(18) : see declaration of 'TabletParameters'
    

    查看生成的代码,大多数错误包含SIGAPI,如下所示:
    SIGAPI * temp;
    

    SIGAPI似乎是#define,它出现在SigLib.h文件中,并用于类定义中,例如:
    class SIGAPI Signature
    

    SigLib.h的定义:
    #ifdef  SIGLIBDLL
    #define SIGAPI  __declspec( dllexport )
    #else
    #define SIGAPI
    #endif
    

    我已经尝试了数小时的Google搜索,以寻求解决方案,但是我没有任何运气。我尚未在SWIG文档中找到任何内容,但老实说,我不确定要查找的内容。

    编辑:

    除了加载额外的标题之外,Giorgos还建议进行更改。它现在似乎可以生成包含所有所需内容的整个包装文件,但是链接到库时出错。

    SigLib.i

    %module SigLib
    %{
        #include "Include\SigLib.h"
    %}
    
    
    %include <windows.i>
    %include "Include\SigLib.h"
    %include "Include\SigPoint.h"
    %include "Include\SigStroke.h"
    %include "Include\TabletParameters.h"
    %include "Include\CircularBuffer.h"
    %include "Include\SerialIoIF.h"
    %include "Include\HidIoIF.h"
    %include "Include\UsbIoIF.h"
    %include "Include\SocketIoIF.h"
    %include "Include\NewSocketIoIF.h"
    %include "Include\SimIoIF.h"
    %include "Include\ProcessSerialData.h"
    %include "Include\CaptureSig.h"
    %include "Include\TabletPoint.h"
    %include "Include\PointBuffer.h"
    %include "Include\TabletInterface.h"
    %include "Include\TabletSampleList.h"
    %include "Include\SigWindowType.h"
    %include "Include\SigFile.h"
    %include "Include\md5.h"
    %include "Include\Utilities.h"
    %include "Include\HotSpot.h"
    %include "Include\HotSpotList.h"
    %include "Include\BitmapCharacter.h"
    %include "Include\CharacterMap.h"
    %include "Include\TiffImage.h"
    %include "Include\LCDGraphicBitmap.h"
    %include "Include\LCDInterface.h"
    

    我做到了,改变了我加载所有内容的方式。现在看来它正在编译,但是我遇到了许多类似以下的链接错误:
    SigLib_wrap.obj : error LNK2019: unresolved external symbol "public: int __thiscall TabletInterface::PointsInPointBuffer(void)" (?PointsInPointBuffer@TabletInterface@@QAEHXZ) referenced in function __wrap_TabletInterface_PointsInPointBuffer
    
    SigLib_wrap.obj : error LNK2019: unresolved external symbol "public: void __thiscall TabletInterface::InitProcessInputData(void)" (?InitProcessInputData@TabletInterface@@QAEXXZ) referenced in function __wrap_TabletInterface_InitProcessInputData
    
    SigLib_wrap.obj : error LNK2019: unresolved external symbol "public: void __thiscall TabletInterface::CloseProcessInputData(void)" (?CloseProcessInputData@TabletInterface@@QAEXXZ) referenced in function __wrap_TabletInterface_CloseProcessInputData
    

    我需要针对SigLib.lib和其他一些lib文件进行链接,但是我不确定如何从我拥有的setup.py文件中执行此操作,并且该方法是否甚至适用于Python。

    最佳答案

    根据SWIG文档的第3.4段:



    在任何特定于Windows的声明之前添加%include <windows.i>可能会解决您的问题。

    09-04 16:17