def test_implicit_unicode_on_windows():
from cffi import FFIError
if sys.platform != 'win32':
py.test.skip("win32-only test")
ffi = FFI()
e = py.test.raises(FFIError, ffi.cdef, "int foo(LPTSTR);")
assert str(e.value) == ("The Windows type 'LPTSTR' is only available after"
" you call ffi.set_unicode()")
for with_unicode in [True, False]:
ffi = FFI()
ffi.set_unicode(with_unicode)
ffi.cdef("""
DWORD GetModuleFileName(HMODULE hModule, LPTSTR lpFilename,
DWORD nSize);
""")
lib = ffi.verify("""
#include <windows.h>
""", libraries=['Kernel32'])
outbuf = ffi.new("TCHAR[]", 200)
n = lib.GetModuleFileName(ffi.NULL, outbuf, 500)
assert 0 < n < 500
for i in range(n):
#print repr(outbuf[i])
assert ord(outbuf[i]) != 0
assert ord(outbuf[n]) == 0
assert ord(outbuf[0]) < 128 # should be a letter, or '\'
评论列表
文章目录