Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Unicode sizeof(TCHAR) == 1???

Unicode sizeof(TCHAR) == 1???

Scheduled Pinned Locked Moved C / C++ / MFC
csstutorialquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dave_
    wrote on last edited by
    #1

    I am building a dll that is supposed to be using Unicode but I am having some problems. I won't go into a lot of detail but here's a quick summary - I am using grid software that requires a CString to be passed into it's SetText() function. I have a structure that has the follwing member: struct MYSTRUCT{ TCHAR szDescription[512]; }; So, when I reach the point where I need to set my grid text, I use the following: CString szTxt(struct.szDescription); It fails indside the CString code in AllocBuffer() where it is actually doing the "new" call. I don't expect anyone to know how to solve this but one thing that jumps out at me is that when I type sizeof(TCHAR) into my watch window, it returns a value of 1. I was expecting 2. I have "UNICODE" and "_UNICODE" defined in the project settings. Any idea?

    D M B 3 Replies Last reply
    0
    • D Dave_

      I am building a dll that is supposed to be using Unicode but I am having some problems. I won't go into a lot of detail but here's a quick summary - I am using grid software that requires a CString to be passed into it's SetText() function. I have a structure that has the follwing member: struct MYSTRUCT{ TCHAR szDescription[512]; }; So, when I reach the point where I need to set my grid text, I use the following: CString szTxt(struct.szDescription); It fails indside the CString code in AllocBuffer() where it is actually doing the "new" call. I don't expect anyone to know how to solve this but one thing that jumps out at me is that when I type sizeof(TCHAR) into my watch window, it returns a value of 1. I was expecting 2. I have "UNICODE" and "_UNICODE" defined in the project settings. Any idea?

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Dave_ wrote: I don't expect anyone to know how to solve this but one thing that jumps out at me is that when I type sizeof(TCHAR) into my watch window, it returns a value of 1. I was expecting 2. I have "UNICODE" and "_UNICODE" defined in the project settings. Try placing #define UNICODE and #define _UNICODE in the stdafx.h file before any other #include statements. It shouldn't matter if those directives are in the code or are in the project settings, but you never know...


      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      1 Reply Last reply
      0
      • D Dave_

        I am building a dll that is supposed to be using Unicode but I am having some problems. I won't go into a lot of detail but here's a quick summary - I am using grid software that requires a CString to be passed into it's SetText() function. I have a structure that has the follwing member: struct MYSTRUCT{ TCHAR szDescription[512]; }; So, when I reach the point where I need to set my grid text, I use the following: CString szTxt(struct.szDescription); It fails indside the CString code in AllocBuffer() where it is actually doing the "new" call. I don't expect anyone to know how to solve this but one thing that jumps out at me is that when I type sizeof(TCHAR) into my watch window, it returns a value of 1. I was expecting 2. I have "UNICODE" and "_UNICODE" defined in the project settings. Any idea?

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        What is in szDescription at that point? Is it in Unicode? Is it properly null-terminated? --Mike-- LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ Strange things are afoot at the U+004B U+20DD

        1 Reply Last reply
        0
        • D Dave_

          I am building a dll that is supposed to be using Unicode but I am having some problems. I won't go into a lot of detail but here's a quick summary - I am using grid software that requires a CString to be passed into it's SetText() function. I have a structure that has the follwing member: struct MYSTRUCT{ TCHAR szDescription[512]; }; So, when I reach the point where I need to set my grid text, I use the following: CString szTxt(struct.szDescription); It fails indside the CString code in AllocBuffer() where it is actually doing the "new" call. I don't expect anyone to know how to solve this but one thing that jumps out at me is that when I type sizeof(TCHAR) into my watch window, it returns a value of 1. I was expecting 2. I have "UNICODE" and "_UNICODE" defined in the project settings. Any idea?

          B Offline
          B Offline
          Blake Miller
          wrote on last edited by
          #4

          Also, you might verify it is not the 'watch' window getting messed up, and do something like this in your (debug) build: size_t szTemp = sizeof(TCHAR); and quickwatch the value of szTemp. Is it 1 or 2? Just to double-check against a wierd anomaly in the watch window's expression parsing or something.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups