none
Accent characters OK in Form application, wrong in console application RRS feed

  • Question

  • I've got a Visual Basic GUI program that calls ExiftoolIO to update exif information.  Now I want to use ExiftoolIO in a console application, linemode thus.  The problem is that if I pass "België" as country to ExifToolIO, there is some translation done by which it becomes"Belgi?" or "België" when ExifToolIO has updated the Exif information of my .JPG file.

    The string "België" is read from a .TXT file and when I display it in hex, I see '42656C6769EB', so that's what I try to pass to ExiftoolIO using "-Country=België".  ExifToolIO is a DLL.  I repeat: when my application is a .NET 'forms' application, all works fine, roughly the same source code as console application fails.

    I'm not a .NET specialist, far from that.  I already found that in the console application I can/should use

         Console.OutputEncoding = Encoding.ASCII   '   Then I get "Belgi?" as result
         Console.InputEncoding = Encoding.ASCII

    or

         Console.OutputEncoding = Encoding.UTF8   '   Then I get "België" as result
         Console.InputEncoding = Encoding.UTF8

    I used the V Studio debugger to see all attributes of "xx" obtained through

      Dim xx = Console.InputEncoding
    I see that the console mode application used codepage 850; the form mode application uses codepage 1252.

    So: how can I change the codepage of my console application to 1250?

    Monday, September 24, 2018 4:37 PM

All replies

  • Did you try Encoding.Unicode too?

    Show some details about the invocation of the tool in your console program. Make sure (using Debugger) that the variables contain valid country before passing the values to the tool.

    • Edited by Viorel_MVP Monday, September 24, 2018 5:35 PM
    Monday, September 24, 2018 5:33 PM
  • Here's an extract of my code


     ExifToolIO.Initiailize()
     ....
     Dim fileid As String, fotoDate As DateTime, t() As String
     t = lijn.Split("|")
     fileid = t(0)
     fotoDate = t(1)
     
     ExifToolIO.Cmd("-P -n -L")     ' Preserve date&time, numerical tags, Latin encoding
     Dim val As String = "", xval As String

     For i = 2 To UBound(t)
         If LSet(t(i), 9) = "-Country=" Then
            val = Mid(t(i), 10) : xval = c2x(val)
            Console.WriteLine(val & " --> " & xval & " length: " & val.Length & "," & xval.Length)
         End If
         Console.WriteLine(t(i))
         ExifToolIO.Cmd(t(i), ReplaceSpaceWithCRLF:=False)
     Next
     Try
       Dim printvalresult As String = ExifToolIO.Execute(fileid).Trim
       If InStr(printvalresult, "1 image files updated") < 1 Then
          Tekst("     ERROR ==> " & printvalresult, TekstLevel.ShowLogDetail)
          ExifRetc = 99
       Else
          Tekst("     ==> " & printvalresult, TekstLevel.ShowLogDetail)
       End If
     Catch ex As Exception
          Tekst("*** ERROR *** ExifToolIO problem for " & fileid & vbCrLf & ex.Message)
          ExifRetc = 199
     End Try

    This produces on the console
    .....
    -CountryCode=BEL
    -Location=Huldenbergstraat
    -Subject=België, Duisburg
    België --> 42656C6769EB length: 6,12
    -Country=België
    -State=Vlaanderen
         ==> 1 image files updated


    Kris Buelens

    Tuesday, September 25, 2018 5:48 AM
  • Oh yes, I tried Encoding.Unicode, but then ExiftoolIO starts looping on the first call to it

    Kris Buelens

    Tuesday, September 25, 2018 5:50 AM
  • Hi,

    try

    1. Open Control Panel -> Change Date, Time or Number -> Open "Area" dialog
    2. Select the Manage tab and click Change System Locale
    3. After selecting what you need to confirm, restart the computer.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, September 26, 2018 2:46 AM
  • Thanks for the hint, but in control panel everything is set the way it should be: "Dutch Belgium", and thus also the "system locale" is set to that.  The list doesn't contain things that look better (thay all contain a countryname

    And, if I'd change something there, how would it explain that

    - a .NET GUI application works perfectly well

    - the same code but in a .NET Console application produces wrong results?

    Basically, I see that the Console program uses codepage 850, bodyname "ibm850" what produces the bad results.  The GUI program uses codepage 1252, bodyname "ISO-8859" and that works fine.  But, I don't know how I can set that from 850 to 1252 in Visual Basic code


    Kris Buelens

    Wednesday, September 26, 2018 8:50 AM
  • To change console encoding:
    Console.InputEncoding = System.Text.Encoding.GetEncoding(1252)


    Wednesday, September 26, 2018 9:02 AM