funcion on C
TCHAR* __stdcall W1251ToUtf8(CHAR* str)//функция пребразования строки из Windows-1251 в Unicode
{
int wsize = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
TCHAR* result = new TCHAR[wsize*sizeof(TCHAR)];
MultiByteToWideChar(CP_UTF8, 0, str, -1, result, wsize);
return result;
}
function declaration in c# project
[DllImport("D://EncodingStringData.dll", EntryPoint = "W1251ToUtf8")]
static extern string W1251ToUtf8(string str);
function call
string TextForEncoding = ReadFromFile();
string OutText = W1251ToUtf8(TextForEncoding);
first time app crash without any reason, then im add try catch
try
{
string TextForEncoding = ReadFromFile();
string OutText = W1251ToUtf8(TextForEncoding);
}
catch (Win32Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
}
and i catch accessviolationexception, now crashing againg without reason.
So anyone know what i need to do?