C# 对字符串ic C进行适当编码的Marshall结构# 我有C++的DLL,我想用在我的C项目中。它叫-它是一个波兰语文本分析器。我已经下载了预编译的dll和.h文件

C# 对字符串ic C进行适当编码的Marshall结构# 我有C++的DLL,我想用在我的C项目中。它叫-它是一个波兰语文本分析器。我已经下载了预编译的dll和.h文件,c#,c++,encoding,marshalling,dllimport,C#,C++,Encoding,Marshalling,Dllimport,问题的核心是:返回结构的字符串缺少波兰语字符 输入:żołnierzom 输出:1个结构的列表 我假设“forma”字符串为: 奥涅兹 我得到: 佐尔尼尔兹 要使用的dll(.h文件)中的主函数: DLLIMPORT InterpMorf*morfeusz_分析(char*tekst); DLLIMPORT是: \ifndef\uuuWin32 #定义DLLIMPORT #否则 /*Windows系统。需要定义DLLIMPORT*/ #伊夫大厦 #定义DLLIMPORT\uuu dec

问题的核心是:返回结构的字符串缺少波兰语字符

输入:żołnierzom

输出:1个结构的列表

我假设“forma”字符串为:

  • 奥涅兹
我得到:

  • 佐尔尼尔兹
要使用的dll(.h文件)中的主函数:

DLLIMPORT InterpMorf*morfeusz_分析(char*tekst);
DLLIMPORT
是:

\ifndef\uuuWin32
#定义DLLIMPORT
#否则
/*Windows系统。需要定义DLLIMPORT*/
#伊夫大厦
#定义DLLIMPORT\uuu declspec(dllexport)
#否则
#定义DLLIMPORT uu declspec(DLLIMPORT)
#恩迪夫
#恩迪夫
此外,我一直在尝试使用这个带有编码选项的函数来解决这个问题

DLLIMPORT int morfeusz_set_选项(int选项,int值);
/*
MORFOPT_编码:
morfeuszèu的“tekst”参数的编码及其分析
字段“forma”、“haslo”和“interp”的结果。可能的
值:UTF-8、ISO-8859-2(默认)、CP1250、CP852。
*/
#定义MORFOPT_编码1
#定义MORFEUSZ_UTF_8
#定义MORFEUSZ_ISO8859_2 88592
#定义MORFEUSZ_CP1250 1250
#定义MORFEUSZ_CP852 852
在C#中,我有(
公共类Morfeusz
):

公共枚举选项
{
编码=1
}
公共枚举编码
{
Utf8=8,
Iso88592=88592,
Cp1250=1250,
Cp852=852
}
[DllImport(“path\\to\\morfeusz2.dll”,EntryPoint=“morfeusz_analysis”)]
公共静态外部IntPtr MorfAnalyse(字符串tekst);
[DllImport(“path\\to\\morfeusz2.dll”,EntryPoint=“morfeusz_set_option”)]
公共静态外部int-MorfeuszSetOption(int-option,int-value);
公共静态int-SetEncoding(MorfeuszEncodings编码)
{
返回MorfeuszSetOption((int)MorfeuszOptions.Encoding,(int)Encoding);
}
从分析返回的映射C#结构:

namespace MorfWrap
{
[StructLayout(LayoutKind.Sequential)]
公共结构InterpMorf
{
公共INTP;
公共INTK;
公共字符串形式;
公共字符串haslo;
公共字符串interp;
}
}
结构中项目的顺序与.h文件中的顺序相同

我尝试用这个属性来修饰字符串,其中XXX是不同的编码,但没有成功

我捕获了这个函数包装器,它将
IntPtr
映射到repo中的结构数组

publicstaticinterpmorf[]分析(字符串文本)
{
SetEncoding(MorfeuszEncodings.Iso88592);
IntPtr morfStruct=MorfAnalyse(文本);
List morf=新列表();
int itemSize=Marshal.SizeOf(typeof(InterpMorf));
整数偏移=0;
InterpMorf InterpMorf;
尝试
{
interpMorf=(interpMorf)Marshal.PtrToStructure((morfStruct+(offset*itemSize)),typeof(interpMorf));
}
捕获(例外情况除外)
{
WriteLine(“参数:{0}错误:{1}Msg:{2}”,文本,例如GetType().ToString(),例如Message);
投掷;
}
//当p==-1时,表示它是树中的最后一个InterpMorf
while(interpMorf.p!=-1)
{
offset++;
添加(interpMorf);
interpMorf=(interpMorf)Marshal.PtrToStructure((morfStruct+(offset*itemSize)),typeof(interpMorf));
}
返回morf.ToArray();
}

您是否尝试将InterpMorf struct中的字符串字段更改为char[]?