|
Hello everyone!
I still don't quite get how C works... I always get weird, and I mean weird errors, like this one:
I have a char* string. It's a filename. If I printf() it, it gives me "x5" or other characters that don't have anything to do with it. But if I open the file, it opens correctly, and I can even display a string on the file...
Why is this? Is there a tutorial or something that explains this kind of stuff? Thanks!
Windows Calculator told me I will die at 28.
|
|
|
|
|
Kixdemp wrote: If I printf()
can you show us your printf() call ?
and, does that char* point to ?
Why donchoo take a peekchur mayn?
OK, cleeeeek
|
|
|
|
|
Interesting - you're learning C ? Do you do embedded work ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
|
|
I need some help converting between TCHAR strings and ASCII strings. (I understand that the actual type for TCHAR is decided by the compiler switches.) In this case, TCHAR is UNICODE. But I have a char* string passed into my function that I need to deal with. My questions:
What's the best way to convert the char* string (array) to TCHAR? I'm doing it one char at a time in a loop, but I am hoping for something more elegant.
How do I handle the ASCII end of string in TCHAR? For example, in one section I need to loop through the characters in the TCHAR string. I want to stop if I hit a new line from the char* string. That's easy in an ASCII string, but in UNICODE... well it's probably just as easy if you know what to look for! Should I be looking for TWO TCHAR characters (0xA and 0x0)? or something else?
Thank you!
|
|
|
|
|
there is an api for the same
MultiByteToWideChar()....
nave
|
|
|
|
|
Not Knuth wrote: How do I handle the ASCII end of string in TCHAR? For example, in one section I need to loop through the characters in the TCHAR string. I want to stop if I hit a new line from the char* string. That's easy in an ASCII string, but in UNICODE... well it's probably just as easy if you know what to look for! Should I be looking for TWO TCHAR characters (0xA and 0x0)? or something else?
wcstombs
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Place the macro USES_CONVERSION at the beginning of your function. You then have access to all of the string conversion macros. You can convert between any of ACSII (A), OLE (OLE), WIDE (W)and TCHAR (T). To convert ASCII to TCHAR do the following.
LPSTR *lpSrc;
LPTSTR *lpDest = A2T(lpSrc);
Similarly T2A, A2W, W2A, A2OLE, etc can be used. You can also put a C after the 2 to get a const string returned.
The good thing about these macros is that if you build the application with _MBCS defined, TCHAR is the same as ASCII so the A2T macros becomes nothing. If you build with _UNICODE defined then it will allocate a buffer and covert to Unicode for you. The memory is allocated on the stack with _alloca, so you can't keep the converted string after the function returns without taking a proper copy of it first. Also don't use inside a loop because it could allocate a lot of memory if the loop iteration is large.
|
|
|
|
|
John Saunders wrote: Place the macro USES_CONVERSION at the beginning of your function
John Saunders wrote: Also don't use inside a loop because it could allocate a lot of memory if the loop iteration is large.
If you use the newer ATL7 conversion macros then you do not have to use USES_CONVERSION and you can safely use the conversion macros inside a loop.
http://msdn2.microsoft.com/en-us/library/87zae4a3.aspx[^]
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
Thanks, this works fine. But I am wondering how the macros work. I followed the code and see that it ultimately ends up at defs for MultiByteToWideChar and others. But of course the code is not shown. So I wonder if this is implemented as just a big lookup table or if there is some better way to approach this.
Obviously this question has become somewhat academic at this point. My initial problem is resolved. But I am just thinking about how I would have implemented this and I don't see a better way than using a big lookup. That seems too clumsy.
|
|
|
|
|
An alternative to using the ATL macros is to use the _bstr_t class. It has constructors that take both ASCII and WIDE character sets, and have overloaded operators for both char* and wchar_t* . It will end up calling the same functions in the end (the MultiByteToWide, etc.) but it easier to read and debug since it isn't a macro.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi,
Im writing a webserver which loads an exe file as cgi application. What im trying to do is not make the window popup each time someone visits the site.
I still need the process visible in taskmanager though...
Heres what im using at this point to load the cgi app and get the std out... which is what i need to do...
char psBuffer[1024];
FILE *pPipe;
send(AcceptSocket, header, strlen(header), 0);
pPipe = _popen("test.exe", "r");
//..other functions
_pclose( pPipe );
Any Help on this matter is appreciated.
|
|
|
|
|
I assume you've got a console window popping up. If you make the exe a normal Win32 project instead of a console one you will not get a console window popping up.
Steve
|
|
|
|
|
Thnx.. I dont think thats going to help in this situation.. because if users were to write thier own cgi.. they would have to do the same.. and such is too much to ask in my opinion... Theres got to be another way to hide the bloody window...
|
|
|
|
|
Assuming you're on XP (or better..) can't you just run your Web Server as a different user - this way the web server will have a seperate desktop, on which any cgi programs will run
|
|
|
|
|
I work with vc++ 6 (don't lough).
I have an MFC project with a resource file created by the MFC wizzard.
I can not run rc.exe on this file. It says "RC: fatal error RC1107 :
invalid usage: use rc /? for help"
I have no problems running rc.exe my own (simple) resource files.
I assume that VC runs rc.exe with some more defines/swithces.
Can anyone tell me how should I run it (and succeed) ?
Thanks
Maurice
|
|
|
|
|
hi all i want to write teh software that block certain site i.e yahoo.com how to do that any help is welcomned.Thanks
Tasleem Arif
|
|
|
|
|
Try writing BHO ( Browser Helpler Objects)
|
|
|
|
|
Hi,
I have a problem with DDK.
when I include every file of DDK (like video.h)
it gives me many errors.
Why?
please help me.
thanks.
Every new thing you learn,Gives you a new personality.
|
|
|
|
|
question now would be what are the errors you are getting?
vipin - Microsoft MVP
http://www.explorewindows.com
|
|
|
|
|
hello there,
I would like to scroll my CListBox (in other words, not a CListCtrl or CListView!) so that a certain item is the topmost visible item in the list (having it visible is not enough). Any ideas? I tried SetScrollPos, and although the range is meaningful, only the scrollbar gets "scrolled" (the bar moves), but the listbox itself doesn't move.
I'm getting quite desperate and all i can find if horizontal scrolling everywhere.
thanks
|
|
|
|
|
I think SetTopIndex or LB_SETTOPINDEX will do what you want.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
After you call SetScrollPos() to set the postion of the scroll bar you have to also send a WM_VSCROLL message to the list box to actually get the list box content to scroll.
pListBox->SetScrollPos(SB_VERT, Position);
pListBox->SendMessage(WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION, Position), NULL);
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
wonderful, both approaches work. Thanks
|
|
|
|