|
I have seen people use these macros on string literals, what are these for?
|
|
|
|
|
typedef WORD WCHAR;
#ifdef UNICODE
typedef WCHAR TCHAR;
#else
typedef char TCHAR;
#endif
so if UNICODE is defined TCHAR is WORD, else its char
|
|
|
|
|
Josh Gray wrote:
so if UNICODE is defined TCHAR is WORD
A typo. You mean TCHAR is WCHAR, of course.
And WCHAR is wchar_t.
--
The Blog: Bits and Pieces
|
|
|
|
|
_T is not the same as _TCHAR or TCHAR in respect to functionality.
_T , TEXT and also L are used to convert string literals to wide or multi-byte type. While _T and TEXT converts to wide if UNICODE is defined and to multi-byte if UNICODE is undefined, L will always force the string literal to wide independent of the UNICODE define.
So,
_T("This will be a string of WCHAR characters "
"if UNICODE is defined and of ordinary char "
"characters if UNICODE is undefined.");
_T("This will also be a string of WCHAR characters "
"if UNICODE is defined and of ordinary char "
"characters if UNICODE is undefined.");
L"This, however, will always be a string of WCHAR characters."; And WCHAR is just a wchar_t .
I highly recommend the article The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)[^] by Joel Spolsky.
--
The Blog: Bits and Pieces
|
|
|
|
|
Thanks. and what is a wide character wchar_t? the question is, when should I care to use these macros? or is it okay to not use them.
also, why do you use "L" like that - what does it expand to?
|
|
|
|
|
Normus wrote:
what is a wide character wchar_t
A UNICODE character. It uses (mostly) 2 bytes of storage instead of 1. Therefore "wide".
Normus wrote:
when should I care to use these macros
If you ask me - always (I come from Europe, where old ASCII is insufficient). If you ask an American - "What's Europe?"
Seriously, if you want anyone who needs a UNICODE alphabet to use your code, then it better be UNICODE enabled.
Normus wrote:
why do you use "L" like that - what does it expand to
L forces UNICODE type of the string literal. For example, code that targets no other OS than Windows CE, which is a UNICODE OS from bottom to top, can use L on all string literals and be sure to always work.
--
The Blog: Bits and Pieces
|
|
|
|
|
dont worry, I am not an american either
Regarding L, I am curious about the C syntax. Is it an operator or a macro or what is it?
Thanks.
|
|
|
|
|
I guess L is an MS compiler extension, because it's not a macro.
--
The Blog: Bits and Pieces
|
|
|
|
|
I want to do one project in VC++, that is in our Laboratory we are using one equipment for Blood Test & Urine Test that Equipment itself generating one report for us. But I want to connect that equipment to my system through Printer port and want to have control over equipment.This is my project brief description.
For to start this project I want some functions which will help to send the Data to equipment and to get response & Data from the equipment.kindly help.
|
|
|
|
|
The first thing to do is to find out if the equipment actually ACCEPTS commands through the printer port (which would be a little unusual - that type of control is usually done through a serial port). Are there any manuals for the equipment that describe the remote control capabilities and message and command formats? If so, then that is the place to start. Once you find out FROM THE MACHINE HOW IT WANTS TO TALK, then you can start the process of how to implement a communication protocol in VC++.
Hope this helps,
John
|
|
|
|
|
Hi
I careate a secondary worker thread in my application.
I read a sample that uses PostQuitMessage(0); to exit the thread..
But I know that I can just use return 0; instead..
when should each method be used ?
|
|
|
|
|
hspc wrote:
I read a sample that uses PostQuitMessage(0); to exit the thread..
But I know that I can just use return 0; instead..
yes there are three way to end worker thread.
1.return(0);
2.AfxEndThread(0);
3.PostQuitMessage(0);
hope u understand
-----------------------------
"I Think It will Work"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
i would use PostQuitMessage() when you want to stop the thread from another thead
for example if you have a CWinThread pointer called pAnotherThread
pAnotherThread->PostQUotMessage(0);
WaitForSingleObject(*pAnotherThread, INFINITE);
this will post the stop message and wait untill the thread has exited
However, if the thread is stopping itself then return(0) is fine
for example
void myThread(LPVOID)
{
while(workToDo)
{
doSomeWork();
}
return 0;
}
|
|
|
|
|
Thank you
this made it clear..
|
|
|
|
|
But
PostQuitMessage() function is not a part of CWinThread
here My VC 6.0 Compiler Error Message
D:\Alok\Currently Working\PhaseTwo\SecureNM9x\NMPClass.cpp(284) : error C2039: 'PostQuitMessage' : is not a member of 'CWinThread'<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxwin.h(3791) : see declaration of 'CWinThread'<br />
Error executing cl.exe.<br />
<br />
SecureNM9x.exe - 1 error(s), 0 warning(s)
-----------------------------
"I Think It will Work"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
use PostThreadMessage(WM_QUIT, 0, 0);
|
|
|
|
|
Shamelessly ripped from Chris Becke:
PostQuitMessage() is typically called to terminate
a UI thread, and UI threads typically need to be terminated when all the
windows depending on the thread have been destroyed.
In situations when there is one frame or parent window the PostQuitMessage
is placed somewhere in the windows destruction code. Either in a message
handler: WM_DESTROY, WM_NCDESTROY, or in some c++ function that gets called
when the window is destroyed - prehaps even the destructor.
Sometimes you might have a situation where more than one top-level window
can exist on the UI thread. In that case you want to do some refrence
counting or some other system - every WM_CREATE or ctor increases a ref
count, every WM_DESTROY, OnHesDeadJim, or dtor the ref count is decreased.
When it hits zero all windows are dead and PostQuitMEssage is called to
terminate the UI thread.
Basically there are many ways to kill a UI thread, and to a large degree the
method used will cahnge according to the requirements of the class
library(s) used and other enviromental constraints.
Chris Becke
|
|
|
|
|
Hi everybody,
I want to export GDI+ bmp files as PDF File format.
I have created GDI+ bmp Objects like this.
Bitmap bmp7(L"myImage.jpg");
Now I want to save this bmp7 Object as PDF File format. u please help me if any one know this.
Thanks.
|
|
|
|
|
Did you find the solution for this problem? If so please let me know.
Thanks.
|
|
|
|
|
Hi
I am currently building an app that maintains a number of objects of a certain class, and the app performs computationally heavy calculations to determine the state of each object. The state for each object is determined by a number of variables: e.g. variables A, B, C, and D. However, since some of the variables, e.g. variable A is actually identical for all objects, I am now implementing A as a private static variable with a public accessor function. This way, I think I can save some computation and storage space.
My question is: is this the correct way to implement the class? Is building a base class and deriving from it better than my current solution?
Thanks!
|
|
|
|
|
hi indrawati,
in your case, the important thing is that what do your variables do. if there are required to be common for all the objects of the particular class, ie they share the same values, then u will have to use them as static. if this is the case then there should be no problem in the design
|
|
|
|
|
I am developing an application in VC++. I am using Read function of CStdioFile class to read Html files and storing the file contents in CString object. Special characters like TM, are being replaced by three characters â„¢ What can be the reason? & how to read such characters in VC++ appliction.
Arvind
|
|
|
|
|
Arvind Jagtap wrote:
I am using Read function of CStdioFile class...
Read() is actually a method of the CFile class. Since .html files are just text, shouldn't you be using CStdioFile 's ReadString() method instead? I guess it depends on what you are doing with the data after it has been read.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hi David,
You are right. CFile has Read function and CStdioFile is derived from CFile. I used ReadString function of CStdioFile also. But still I am not able to read the special character ™ properly. This character is present in Html file name and its corresponding folder name. So this character is also present in Html file contents as the folder name appears in Html file many times.
I want to get the images present in Html file. I am parsing Html files and SRC attributes of tags. But the relative path contains ™ character. After reading this Html file by using any method (Read/ReadString), this character splits into three characters â„¢ and relative path of image becomes invalid and program fails. So I want to know why this happens and is there a workaround for this problems.
Thanks & regards,
Arvind
|
|
|
|
|
Hi David,
For example you can browse the following link and save this as an Html file on your Hard Disk. You will find ™ character in it. Try to open this file by using CStdioFile/CFile class, and read the contents of file. ™ character splits into three characters. If you find any solution please let me know.
http://products3.3m.com/catalog/us/en001/auto_marine_aero/aerospace/node_GSCT5B6VLBbe/root_GST1T4S9TCgv/vroot_GSNNJ6NQDKge/gvel_JTZPWXR1L1gl/theme_us_aerospace_3_0/command_AbcPageHandler/output_html
One more strange observation. If you try to save this file at another location in Hard disk (by using save as option), it can't save. I think becuase ™ character, this is happening.
Thanks and regards,
Arvind
|
|
|
|