出于低级目的,我需要从任意地址构造一个ctypes指针,以整数形式给出.例如:
INTP = ctypes.POINTER(ctypes.c_int)
p = INTP(0x12345678) # i *know* this is the address
Run Code Online (Sandbox Code Playgroud)
但所有这些尝试都会导致
TypeError: expected c_long instead of int
Run Code Online (Sandbox Code Playgroud)
我能做些什么来克服这个问题吗?如果有人想知道我为什么需要这个,那么就是为了OVERLAPPED
从一个win32file.PyOVERLAPPED
用于集成ctypes暴露的函数和win32file包装的API 来提取结构.
谢谢,
-Tomer
我正在尝试做一个非常简单的任务:获取一个unicode-aware wstring
并将其转换为a string
,编码为UTF8字节,然后采用相反的方式:获取string
包含UTF8字节并将其转换为unicode-aware wstring
.
问题是,我需要它跨平台,我需要它与Boost一起工作......而我似乎无法想办法让它工作.我一直在玩弄
试图将代码转换为使用stringstream
/ wstringstream
而不是任何文件,但似乎没有任何工作.
例如,在Python中它看起来像这样:
>>> u"????"
u'\u05e9\u05dc\u05d5\u05dd'
>>> u"????".encode("utf8")
'\xd7\xa9\xd7\x9c\xd7\x95\xd7\x9d'
>>> '\xd7\xa9\xd7\x9c\xd7\x95\xd7\x9d'.decode("utf8")
u'\u05e9\u05dc\u05d5\u05dd'
Run Code Online (Sandbox Code Playgroud)
我最终追求的是:
wchar_t uchars[] = {0x5e9, 0x5dc, 0x5d5, 0x5dd, 0};
wstring ws(uchars);
string s = encode_utf8(ws);
// s now holds "\xd7\xa9\xd7\x9c\xd7\x95\xd7\x9d"
wstring ws2 = decode_utf8(s);
// ws2 now holds {0x5e9, 0x5dc, 0x5d5, 0x5dd}
Run Code Online (Sandbox Code Playgroud)
我真的不想在ICU上添加另一种依赖关系......或者根据我的理解,应该可以使用Boost.
一些示例代码将非常感谢!谢谢