如何將C中的基於char**
的數組轉換爲C#中的等效類型?如何將基於char **的數組從基於C的dll轉換爲c#等價物?
我有一個函數,它需要一個char**
緩衝區並用正確的數據填充它的DLL。
我使用的是C#應用程序中該DLL使用DllImport
,當我需要指定return type
或argument type
這種功能的問題開始。
C#中的哪一個類型等價於C char**
數組?
我應該做什麼和什麼?
更新:
這是位於我的DLL裏面我的C函數:
CDLL_API wchar_t** GetResults(wchar_t* word, int* length, int threshold = 9);
而這兩個函數調用下面的函數來獲得自己的價值:
wchar_t** xGramManipulator::CGetNextWordsList(const wchar_t* currentWord, int threshold)
{
wstring str(currentWord);
auto result = GetNextWordsList(str, threshold);
return GetCConvertedString(result);
}
wchar_t ** xGramManipulator::GetCConvertedString(vector< wstring> const &input)
{
DisposeBuffers();//deallocates the previously allocated cStringArrayBuffer.
cStringArraybuffer = new wchar_t*[input.size()];
for (int i = 0; i < input.size(); i++)
{
cStringArraybuffer[i] = new wchar_t[input[i].size()+1];
wcscpy_s(cStringArraybuffer[i], input[i].size() + 1, input[i].c_str());
cStringArraySize++;
}
return cStringArraybuffer;
}
我用wchar_T **,但我認爲不應該有任何區別C#方面(因爲c#默認支持unicode!所以如果它的不同請寄給我)
您是否嘗試過使用ref字符串? –
'string []'should work afaik – x4rf41
不,我完全不知道它。 – Breeze