开发者

Porting ctypes-based code snippet from linux to windows

I have the following code that works under linux. I want to port it to Windows

but i have no idea where to look for.

import os
import sys
import ctypes 
import ctypes.util
MAX_CHARS = 1000    # maximum number of characters to read

if __name__ == "__main__":
    libc = ctypes.CDLL("libc.so.6") # LINUX
    fd = libc.open(sys.argv[0], os.O_RDONLY)
    buffer = " " * MAX_CHARS
    num_chars_read = libc.read(fd, buffer, MAX_CHARS)
    print buffer[:num_chars_read]
    libc.close(fd)

    # ALL OF THIS GIVES WRONG DLL's 'UNDER WINDOWS
    #libc = ctypes.CDLL(ctypes.util.find_library('开发者_如何学运维c'))
    #libc =  ctypes.windll.kernel32 # WINDOWS
    #libc =  ctypes.windll.user32 # WINDOWS
    #libc =  ctypes.windll.shell32 # WINDOWS
    #libc =  ctypes.windll.gdi32 # WINDOWS
#libc =  ctypes.cdll.msvcrt # WINDOWS

Any idea in which DLL i need to look for 'open' and 'read' calls?

Many thanks


These slides indicate that this will work:

>>> from ctypes import *
>>> libc = cdll.msvcrt

I can then access libc.printf, and libc.fopen, but not open or read, though libc._open and libc._read are available. Perhaps an issue with calling conventions?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜