Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Finally, I got rid of the problem!</p> <p>The real reason of the problem was the encoding string. Here are all the changes I made to improve my code.</p> <p>If you see suspicious things I do that could be improved, feel free to comment</p> <p>my MainApplication:</p> <pre><code>private void processImport() { string[] fields; string field ; string temp = ""; byte[] tempByte; TextFieldParser parser = new TextFieldParser(textbox_csv.Text, System.Text.Encoding.UTF8); parser.TextFieldType = FieldType.Delimited; parser.SetDelimiters(";"); while (!parser.EndOfData) { fields = parser.ReadFields(); field = fields[0]; temp = RemoveDiacritics(field).ToUpper(); //this line is very important. It seems to change the Encoding of my string to Unicode. temp = temp.Normalize(NormalizationForm.FormC); field = myVbDll.MyWrappedFunction(temp, false); } parser.Close(); } //Transforms the culture of a letter to its equivalent representation in the 0-127 ascii table, such as the letter 'é' is substituted by an 'e' public string RemoveDiacritics(string s) { string normalizedString = null; StringBuilder stringBuilder = new StringBuilder(); normalizedString = s.Normalize(NormalizationForm.FormD); int i = 0; char c = '\0'; for (i = 0; i &lt;= normalizedString.Length - 1; i++) { c = normalizedString[i]; if (CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark) { stringBuilder.Append(c); } } return stringBuilder.ToString().ToLower(); } </code></pre> <p>Part of VB.net Dll, called by my c# program :</p> <pre><code>Public Class myVbDll &lt;DllImport("Wrapper.dll", CharSet:=CharSet.Unicode)&gt; Public Shared Function MyWrappedFunction (ByVal nom As String, ByVal opt As Boolean) As String End Function End Class </code></pre> <p>part of C++ wrapper, called by VB.net Dll :</p> <pre><code>typedef void (*MYFUNCTION)(CString&amp;, CString&amp;, BYTE); MYFUNCTION Myfunction; LPWSTR _stdcall MyWrappedFunction(LPWSTR ValInput, BYTE opt) { HINSTANCE gLibtestDLL=NULL; CString S_ValInput(ValInput); CString S_resultat; gLibtestDLL = AfxLoadLibrary(TEXT(".\\test.dll")); if(gLibtestDLL == NULL) { MessageBox(NULL, TEXT("unable to load test.DLL"), TEXT("Error"),MB_OK | MB_ICONINFORMATION); return NULL; } Myfunction = (MYFUNCTION)GetProcAddress(gLibtestDLL, "Myfunction"); if (Myfunction == NULL) { MessageBox(NULL, TEXT("Can't find Myfunction."), TEXT("Error"),MB_OK | MB_ICONINFORMATION); return NULL; } //****************************************************************** S_resultat.Format("%64c", ' '); Myfunction(S_ValInput , S_resultat , opt); //Run MFC function S_resultat.TrimRight(); S_resultat.ReleaseBuffer(); char* tmp = (char*) CoTaskMemAlloc((S_resultat.GetLength()*2)+1); memset(tmp,0,sizeof(tmp)); strcpy_s(tmp, (S_resultat.GetLength()+1), S_resultat.GetBuffer(S_resultat.GetLength())); S_resultat.ReleaseBuffer(); wchar_t wtext[1024]; memset(wtext,0,sizeof(wtext)); mbstowcs(wtext, tmp, strlen(tmp)+1);//Plus \0 LPWSTR resultat = wtext; AfxFreeLibrary(gLibtestDLL); return resultat; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload