Вы не можете использовать wstring
. Это ctypes
не cpptypes
. Используйте wchar_t*,size_t
для передачи буфера в C ++, а не wstring
.
Пример DLL:
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
#define API __declspec(dllexport)
extern "C" {
API void helloWorld(wchar_t* buffer, size_t length)
{
// Internally use wstring to manipulate buffer if you want
wstring buf(buffer);
wcout << buf.c_str() << "\n";
buf += L"(modified)";
wcsncpy_s(buffer,length,buf.c_str(),_TRUNCATE);
}
}
Пример использования:
>>> from ctypes import *
>>> x=CDLL('x')
>>> x.helloWorld.argtypes = c_wchar_p,c_size_t
>>> x.helloWorld.restype = None
>>> s = create_unicode_buffer('hello',30)
>>> x.helloWorld(s,len(s))
hello
>>> s.value
'hello(modified)'