C programming - enum switch case with TCHAR

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cacc
    New Member
    • Jul 2014
    • 1

    #1

    C programming - enum switch case with TCHAR

    I am doing a win32 program with C and I do not know how to do a enum and switch case with UNICODE.
    I receive from a named pipe a structure
    {
    TCHAR UtilOrigem[10];
    TCHAR Comando[3]; // Comando
    TCHAR Argumento1[10];
    }cmd;

    cmd.comando have values 00, 01, 02 .....

    And I want to do a switch case with cmd.comando.

    Please help me.
    Thanks
    Carlos
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    convert the cmd.comando to an int then use that in a switch?
    Code:
    int i=cmd.comando[0]*100+cmd.comando[1]*10+cmd.comando[0];
    switch (i)
    {
      .....
    if the cmd.comando values of are ASCII characters you will need to subtract '0' in each case

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Unicode applies to strings. You would use WideCharToMulti Byte convert your Unicode string to a multi-byte string and convert that to an integer to use in your switch.

      Research these functions:
      Code:
      http://msdn.microsoft.com/en-us/library/windows/desktop/dd374085(v=vs.85).aspx
      BTW TCHAR assumes you will support both ASCII and Unicode in your program. If you are going to support only Unicode, then you wouldn't use TCHAR. The TCHAR macros expand differently if you compile with or without Unicode support in your Visual Studio project. I suspect you don't need TCHAR at all and can safely use WSTR instead.

      Comment

      Working...