|
Don't go around casting. Use this:
AfxMessageBox(_T("Something"));
The _T (from <tchar.h> ) is a macro which makes the string MBCS or UNICODE depending on what your build is targeting.
Steve
|
|
|
|
|
Thanks a bunch. May i also know why this happens for the new version(2005) and not the old one(v 6)?
|
|
|
|
|
If you make a project in MSVC6 and look at the compiler settings you'll see that it has the _MBCS defined. With Visual Studio 2005 instead of _MBCS UNICODE and _UNICODE are defined. The default for MSVC6 projects is to use multibyte strings but for 2005 it is Unicode.
Steve
|
|
|
|
|
Thanks again Steve. As you can see, i'm fairly new to programming with visual studio. I'm having another problem with writing to files. Like before, this code works perfectly well in MSVC6 but its giving me problems in VS2005. I'll only show half the code for simplicity.
CString tempbuf;
tempbuf = "Job number,";
file.Write((LPCTSTR)tempbuf,tempbuf.GetLength());
file.Close;
When i open the file, it has 'J o b n u' in it. Do you know how i can fix this problem?
Thanks for your time.
|
|
|
|
|
The problem here is that you want to write the file in ANSI but you're compiling for Unicode. There are two ways you can go:
- Convert the Unicode string before writing.
- Change the project from Unicode to MBCS.
To make the second select "Project->Settings" and select the "C/C++" tab. Now erase the "_MSBS" "_MBCS" from the "Preprocessor definitions" edit box and add "UNICODE, _UNICODE" in its place. These steps are for MSVC6 but you should be able to adapt them.
Steve
-- modified at 4:14 Sunday 25th June, 2006
|
|
|
|
|
I couldn't find 'settings' in 'Project'. So the way i did it was i right-clicked the project node in Solution Explorer and clicked Properties.
There, i went to "Configuration Properties->C/C++->Preprocessor". I think it should be the same but they only had "WIN32;_WINDOWS;_DEBUG"
in the "Preprocessor definitions" edit box. I tried to add "UNICODE,_UNICODE" but it still didn't solve the problem.
|
|
|
|
|
Sorry, I got that the wrong way:
Remove "UNICODE,_UNICODE" and add "_MBCS".
Steve
|
|
|
|
|
I believe that my interface is slightly different from yours. First of all, in the preprocessor definitions box, there isn't any "UNICODE,_UNICODE". Whats there is: "WIN32;_WINDOWS;_DEBUG".
BUT, when i clicked on the "..." button at the right hand side of the box, there is a checkbox saying "Inherit from parent or project defaults" and a box that lists the inherited values: "_AFXDLL,UNICODE,_UNICODE".
I unchecked this box and added "_AFXDLL" and "_MBCS" to the original list of preprocessor definitions.
The list now looks like this: "WIN32;WINDOWS;_DEBUG;_AFXDLL;_MBCS;$(NOINHERIT)"
Now when i compile, this error comes up:
msvcrtd.lib(wcrtexew.obj) : error LNK2019: unresolved external symbol _wWinMain@16 referenced in function ___tmainCRTStartup
|
|
|
|
|
I haven't got VS2005 so I can't help you any further, sorry. Someone as CP must know how to change a Unicode project to MBCS using VS2005. Good luck.
Steve
|
|
|
|
|
Its ok.. What about your 1st solution: convert the unicode string before writing?
How can i do that?
|
|
|
|
|
Try this:
CT2CA(static_cast<LPCTSTR>(str))
See here[^] for details.
Steve
|
|
|
|
|
|
hello!
i change header of a pe file and i add a new section for this file. this file execute correct and no problem. but kaspersky (anti virus) detect this file as a type_win32 virus!!!
why???
Zo.Naderi-Iran
|
|
|
|
|
I would guess it interprets the file beging edited as an attack. This in understandable as this is the kind of trick a virus would use.
Steve
|
|
|
|
|
Virus checkers can give false positives, they are not 100% correct
I had one that claimed an empty directory was a virus, it was Microsoft's latest, once the 'fault' was reported they fixed their virus checker!
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for - in order to get to the job you need to pay for the clothes and the car, and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
|
|
|
|
|
What's the function that return the caption of the windows that is focusing in the system.
|
|
|
|
|
|
If you want the window that has focus in the entire system GetFocus will not do the trick. To quote MSDN:
"GetFocus returns the window with the keyboard focus for the current thread's message queue. If GetFocus returns NULL, another thread's queue may be attached to a window that has the keyboard focus. "
If you want the window with focus in the whole system and not just the calling thread (and threads that have been attached to it through the AttachThreadInput function) you can do so through the GetGUIThreadInfo API. i.e.
GUITHREADINFO gti;
bti.cbSize = sizeof(GUITHREADINFO);
if (GetGUIThreadInfo(NULL, >i))
{
HWND hFocus = gti.hwndFocus;
}
I don't think this works on 95 (does on 98) however.
Steve
|
|
|
|
|
He can use GetActiveWindow()>/code> <code>GetFocus()
whitesky
|
|
|
|
|
The OP asked for the window "that is focusing in the system". If he wants the window that has focus throught the entire system then GetFocus will not work. It only returns the window that has focus and was created by the calling thread or a thread attached to the calling thread via the AttachThreadInput function, as I said. Try it and see. The documentation argees with me (see here[^]):
"The GetFocus function retrieves the handle to the window that has the keyboard focus, if the window is attached to the calling thread's message queue."
Steve
|
|
|
|
|
Hello everyone!
Alright... How does this memory thing work? I set a char* to a string. I restarted the program, displayed the string without setting it to anything, and there it was! Is that why I must use the free() function? Thanks!
If that's so - now I understand what C#'s "memory management" meant... In C++ you gotta do it yourself! I see...
\|/ Thrift Store Floppy Collection \|/
(Server currently down due to mainteneance, aka comp not detecting monitor and acting weird)
|
|
|
|
|
In the first run, how did you assign the char* pointer?
char *str = "12345"; or
char *str = new char[5];
sprintf(str, "12345", 5);
A little sample code would be helpful.
Best,
Jun
|
|
|
|
|
I did this:
char *str;<br />
str = malloc(5);
Thanks!
Note: I used malloc() instead of new char[] because the latter is C++ only, and I'm on C...
\|/ Thrift Store Floppy Collection \|/
(Server currently down due to mainteneance, aka comp not detecting monitor and acting weird)
|
|
|
|
|
Thanks. I overlooked low-level C routines.
Return to you first post. Yes, that is basically what .NET GC means. It manages the .NET heap, but the native heap remains unmanaged.
Best,
Jun
|
|
|
|
|
Oohh... Alright, so free() 'ing the strings after using will show random chars instead the next time I run the program? Thanks!
PD: Teh C lingo is getting exciting!
\|/ Thrift Store Floppy Collection \|/
(Server currently down due to mainteneance, aka comp not detecting monitor and acting weird)
|
|
|
|