|
Does anybody know how to convert a CString into a (unsigned short *) ??
Thanks in advance!
|
|
|
|
|
I'm not really sure why you'd want to do this, but...
CString sDuh = "howdy partner";
unsigned short *pDuh = (unsigned short *)(LPCTSTR) sDuh;
Jeremy L. Falcon
"The One Who Said, 'The One Who Said...'"
<nobr>
Homepage : Sonork = 100.16311 01000010011011110110001000100000011101110110000101110011 00100000011010000110010101110010011001010010111000000000
|
|
|
|
|
Duh! Bug alert, if it is not compiled with _UNICODE defined. Here is one:
USES_CONVERSION;
CString sDuh = "Howdy partner";
unsigned short *pDuh = T2W((LPCTSTR)sDuh);
I don't think you have to include anything if you have an ATL or MFC project. I don't know for other kind of projects.
Also, the conversion macros don't need cleanup, because memory is allocated on the stack.
If you are using ATL 7.0 (with Visual Studio.NET), those macros are declared deprecated. But there is a replacement.
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
hph wrote:
convert a CString into a (unsigned short *)
Huh? Why would you want to do that?
I presume you mean LPCTSTR, don't you?
then you don't have to cast it explicity. It's implicitly done for you.
Nish
Check out last week's Code Project posting stats presentation from :-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
|
|
|
|
|
Thanks for the people who answered my questions before ^^.
But I still have another problem. In the CPacket class, I need to add a static CRITICAL_SECTION m_cs (protected) to guard the m_counter. However, which place is good for me to put InitializeCriticalSecion(&m_cs) and DeleteCriticalSesion(&m_cs)? Is there any class initialization functions in C++ ?
Thanks
Hiya, Everybody ^^
|
|
|
|
|
You can do this to know if you need to initialized the critical section
if ( !m_cs.DebugInfo )
InitializeCriticalSection(&m_cs);
|
|
|
|
|
Ack, no don't do this. Race conditions in a MT program.
Very bad idea.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Unlike Java, there's no facility in C++ for static construction/destruction. One can make it up nevertheless as this example shows:
class myclass
{
public:
static CRITICAL_SECTION cs;
private:
friend my_class::static_initializer;
struct static_initializer
{
static_initializer();
~static_initializer();
};
static static_initializer si;
};
CRITICAL_SECTION my_class::cs;
my_class::static_initializer::static_initializer()
{
InitializeCriticalSection(my_class::cs);
}
my_class::static_initializer::~static_initializer()
{
DeleteCriticalSection(my_class::cs);
}
my_class::static_initializer my_class::si;
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
|
I tryied to pass information from edit box to a CString variable. When the debug code is generated it works but when I generate the release code the variable is empty!!
By the way there is VC++ 6 it works.
for example :
CEdit m_edit;
.............
.........
void Cdial2View::OnBnClickedButton1()
{
int nLineLenght = m_edit.LineLength();
CString m_Str;
m_edit.GetLine(0,m_Str.GetBuffer(nLineLenght));
::MessageBox(NULL,(LPCTSTR)m_Str,"VALUE",MB_OK);
}
In VC++. Net this code worked when I used Multi thread Debug runtime library and it won't worked when I used multi thread runtime library.
geagle
|
|
|
|
|
I have a group box with a caption on a dialog. In the dialog editor it looks fine, the text is on top of the border so there is no line through the text caption. At runtime it appears the border is on top of the text, as the text has the line from the border drawn through it. I created this group box using the dialog editor. I have other group boxes on other dialogs which display correctly at runtime. However, I cannot see any properties that I have set differently between the two dialogs.
Does anyone know how to display this dialog so the text does not have the line from the border through it?
Thanks in advance,
Bob
|
|
|
|
|
the only time i have seen this is when the caption is a separate static control that you have placed in the tab order after the group box (i think its after)
either change the tab order to the other way round or use the built in caption of the group box
situations to avoid #37: "good morning ... how many sugars do you take in your coffee ... and what was your name again?"
coming soon: situations to avoid #38: "...and the dog was there too?"
|
|
|
|
|
That's the problem, I am using the built in caption of the group box. I'm seeing it display two different ways in two different dialogs.
|
|
|
|
|
Hi..
I write a static linked MFC application and i need some advice about reducing the .exe size
I used the compiler optimization option (minimum size) but the release build is still big.
is there any other options?
also is it posible to tell if there are some coding practices to reduce the size ?
can i delete some unnecessary wizard code?
|
|
|
|
|
If it's not completely necessary, link in the MFC libraries dynamically. That should reduce your executable size considerably.
-Mike Zinni
Software Engineer
email: mzinni@rimail.com
AIM: zin9999
|
|
|
|
|
|
Search this forum for the word 'liposuction' and you will find a couple of interesting leads.
|
|
|
|
|
|
Michael Dunn wrote:
/opt:nowin98
What's that do? It removes any code required for backward 98 compatibility???
Nish
Check out last week's Code Project posting stats presentation from :-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
|
|
|
|
|
RTFM
But seriously - the default behavior of the VC6 linker is to make the PE sections aligned on 4K boundaries, which makes the EXE load faster after being defragged by the Win 98 defragger (which has that gimmick of placing clusters where they'll be read in faster from disk). Adding that switch goes back to the pre-v6 behavior of 512-byte boundaries, which makes for a smaller EXE (less padding within the file to get to 4K boundaries), in exchange for alleged slower loading times which no one will notice with today's hardware.
--Mike--
Buy me stuff!
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Big fan of Alyson Hannigan and Jamie Salé.
|
|
|
|
|
thank u
i wish to know if it is possible to reduce the size if i make my own classes enstead of MFC
for example writing my own CFIle?
|
|
|
|
|
I need to Trap the above, so that the user has to enter a pasword to exit the program, I allready trap PreTranslateMessage but "ALT + F4" must be decoded befoer this is called
It should be easy.........
Rich
|
|
|
|
|
What about just using an accelerator?
|
|
|
|
|
Just intercept WM_CLOSE . I think that should work for ALT+F4, close button, close context menu, etc.
--------
all the modern things
have always existed
they've just been waiting
to come out
and multiply
and take over Björk, The Modern Things
|
|
|
|
|
Thanks for that, the easiest is always the best.
Rich
|
|
|
|