Pythonのお勉強 Part13
■ このスレッドは過去ログ倉庫に格納されています
0174デフォルトの名無しさん
2006/09/20(水) 13:16:27import ctypes
def send(path, s):
dll = ctypes.windll.kernel32
handle = dll.CreateFileA(
path,
0x40000000, # GENERIC_WRITE
0x00000001, # FILE_SHARE_READ
None,
3, # OPEN_EXISTING
0x00000080, # FILE_ATTRIBUTE_NORMAL
None)
if handle == -1:
raise IOError, "CreateFileA failed: " + path
try:
s = s.encode("mbcs")
while s:
written = ctypes.c_int()
if not dll.WriteFile(handle, s, len(s), ctypes.byref(written), None):
raise IOError, "WriteFile failed: " + path
s = s[written.value:]
finally:
dll.CloseHandle(handle)
Windowsのメールスロットに書き込むのにこういうのがいるんだけど、
Cで拡張ライブラリ書かなくてもできるようになったのはお手軽。
■ このスレッドは過去ログ倉庫に格納されています