c_extend

import sys
from ctypes import *


class FloatBits(Structure):#结构体嵌套
    class _Bits(Structure):
        _fields_ = [('M', c_uint, 23),
                   ('E', c_uint, 8),
                   ('S', c_uint, 1)
                   ]
    _fields_ = [('value', c_float),
               ('bits', _Bits)
               ]


class ST_TEST(Structure):
    _fields_=[('min', c_double),
              ('mix', c_double),
              ('pstribg',c_char_p),
              ('pstriag', c_char*10)]

class ST_LINACCD1M(Structure):
    _fields_=[('iSTVersion',c_int32),
              ('szVersionID', c_char*20),
              ('szReleaseDate', c_char*20),
              ('szCompanyName', c_char*50),
              ('szAuthor', c_char*20),
              ('szInstrType', c_char*20),
              ('szProjectName', c_char*20),
              ('szReserved', c_char*20),
              ('szNotused', c_char*20)]

if __name__ == "__main__":
    SPAMSDLL = cdll.LoadLibrary('D:\\testSPAMSDLL\\SPAMSFileLib\\Release\\SPAMSFileLib.dll')
    hFile=SPAMSDLL.MS_OpenFile(b'D:\\testSPAMSDLL\\2017-06-06-22-15-20\\2017-06-06-22-15-20.atof')
    if (0!=hFile):
        b=ST_LINACCD1M();
        SPAMSDLL.MS_GetVersion(hFile,pointer(b))
        SPAMSDLL.MS_CloseFile(hFile)
    MyDLL=cdll.LoadLibrary("D:\\Documents\\Visual Studio 2010\\Projects\MyDLL\\Release\\MyDLL.dll")
    a=ST_TEST();
    ST_INSTRUMENT_INFO = MyDLL.getStruct(pointer(a))
    a=ST_TEST();

1.定义结构体,一定要用_fields_
2.文件路径前加b,表示转成二进制

extension modules, sometimes called native modules. Unlike Python modules, these are not .py files containing Python source code - they are .pyd files that contain native, platform-specific code, typically written in C

When you see "unable to find vcvarsall.bat", it means you're installing a package that has an extension module, but only the source code. "vcvarsall.bat" is part of the compiler in Visual Studio that is necessary to compile the module.

When you use pip to install your package, if a wheel is available for your version of Python, it will be downloaded and extracted. For example, running pip install numpy will download their wheel on Python 3.5, 3.4 and 2.7 - no compilers needed!

posted @ 2018-01-29 17:29  blog_hfg  阅读(236)  评论(0)    收藏  举报