MATLAB wchar_t等效类型

时间:2014-09-11 22:36:22

标签: matlab loadlibrary wchar-t

C代码存储在DLL中。我可以使用loadlibrary函数在MATLAB中加载DLL。我无法将wchar_t * []参数传递给函数。我不知道如何在MATLAB中创建这种数据类型。有谁知道如何创建这种类型以传递给calllib函数?

MATLAB代码:

loadlibrary('test.dll', 'test.h');

str = '0';
ptr = libpoiner('voidPtrPtr', [int8(str) 0])

calllib('test.dll', 'testFunction', ptr) %this parameter does not match the wchar*[] type

outVal = ptr.Value

C代码:

void testFunction(wchar_t* str[])
{
    str[0] = L"test";
}

输出:

MATLAB允许该功能完成。 outVal变量用垃圾值填充。

2 个答案:

答案 0 :(得分:0)

如果您能够修改C头文件,可以尝试以下操作:

  1. 调整头文件以将所有wchar_t *转换为无符号短*。

  2. 在MATLAB方面,相应的类型将是一个uint16数组。

  3. 然后您可以将uint16数组强制转换为char。

答案 1 :(得分:0)

我明白了。我将MATLAB代码更改为以下内容:

loadlibrary('test.dll', 'test.h');

str = '0';
ptr = libpoiner('voidPtrPtr', [uint16(str) 0])

calllib('test.dll', 'testFunction', ptr) %this parameter does not match the wchar*[] type

outVal = ptr.Value

expectedOutput = char(outVal); %convert to ASCII

它输出十进制的值让我困惑。当我将它们转换为ASCII时,一切都有意义。

相关问题