|
I'm programing in C language.
I'd like to use the wsprintf function with a LPTSTR variable.
here my code:
void GetDescription (LPTSTR Description)
{
char TypeRes[100];
char Resources[100];
lstrcpy (TypeRes, "Bitmap");
lstrcpy (Resource, "file.bmp");
Description=wsprintf (Description, "<%s : %s>", TypeRes, Resources);
}
It doesn't work! The variable Description is empty or invalid. But I have to use LPTSTR not char[xxx], otherwise, my program is very slow and I get a memory error.
Help me!!!!!!
Appstmd
|
|
|
|
|
If you use wsprintf() I guess you have defined UNICODE and _UNICODE, in that case you can not ude char, but should instead use wchar_t.
Description=wsprintf() fails, wsprintf returns the number of characters the function put in to a string, not the string itself, so you should use something like int result = wsprintf (Description, "<%s : %s>", TypeRes, Resources);.
Make sure that Description are large enough to contain the text you pun into it with wsprintf()
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
If you use wsprintf() I guess you have defined UNICODE and _UNICODE, in that case you can not ude char, but should instead use wchar_t.
This is not correct. The function has ANSI and UNICODE versions. In this case, the w does not refer to a wide character variant. It refers to a windoze-specific function that resides in user32.dll and is not part of the C runtime library.
|
|
|
|
|
Oops
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
The rest of your answer was mostly right though. The assignment to Description is inappropriate and is causing the problem.
FWIW, wsprintf is mostly like sprintf but it does not support floating point values.
|
|
|
|
|
Thks a lot!
The code now works perfectly. My variable Description was not large enough ... Here the changes:
Lenght=lstrlen(TypeRes)+lstrlen(Resource);
Description = (char*) malloc(Lenght);
Description[Lenght]='\0';
wsprintf (Description, "<%s : %s>", TypeRes, Resource);
Appstmd
|
|
|
|
|
The code is still wrong, you don't allocate enough space for the Description string. Look at the wsprintf() format - you have the two substrings, two angle brackets, two spaces, and a colon. Plus the terminating null. So you should malloc (lstrlen(TypeRes) + lstrlen(Resource) + 6)*sizeof(TCHAR)
--Mike--
Fetchez la vache!
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan and Jamie Salé.
|
|
|
|
|
You should:- use the
TEXT() or _T() macros for all your string literals - use
TCHAR instead of char - include
tchar.h - and if you have
UNICODE and _UNICODE defined (ie you are using unicode version of wsprintf ), make sure you check the "Display unicode strings" options under the Debug tab of the VC++'s Options dialog.
PS. Are you sure you have a valid buffer in Description ?
PPS. Just saw you assigning Description from the results of wsprintf . Did you read the docs at all? LPTSTR is not a string class ! You are making the Description pointer to point to some invalid address after the function call.
|
|
|
|
|
Assuming the calling code is passing a valid buffer in the Description parameter, take out the "Description =" part and it will work. Then do all the TCHAR-related stuff the other posts have mentioned (although they are wrong about Unicode; wsprintf() is not a Unicode-only function, that would be swprintf()).
--Mike--
Fetchez la vache!
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan and Jamie Salé.
|
|
|
|
|
Hahaha... I am Alpha Intelligence(AI). And I'm a chinese boy.
I want to write a software like "Clone CD"?
So I want to know about CD's files structs. But you see, I don't know how can I get it. And Where I can get it.
Thanks a lot!
I want to become programmer!!!
|
|
|
|
|
CloneCD does a raw copy of the CD, it completely ignores any file structure (or differences between CD-DA and CD-ROM). If you decide that you don't want to do another CloneCD after all, the file system on CD-ROMs is defined in the standard ISO 9660. A draft version is viewable here There are various extensions to handle long file names, bootable discs, etc. See www.cdrfaq.org for more information.
|
|
|
|
|
Hi,
I am fairly new to anything involving graphics! But been playing around GDI+
What i want is to merge two images, using transparency. Can someone give me an overview of doing this in GDI+ using alphablending.
Cheers
Rich
|
|
|
|
|
I'm not sure if you can select a bitmap and specify transparency when you draw it. I seem to recall I did it using direct pixel access ( GetBitmapData, from memory is how to do that ), and then merging the pixels myself.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
|
|
|
|
|
Hi,everybody here. I'm very sorry I am a Chinese boy. So I have poor English level to understand the means in this wonderful websuit. But I like this web very much.
But now, I have some difficult in creating my DLL files. The question is: Could I create DLL file with Borland Turbo C (version:2.0)? And can I use Visual C++ to write C code? Haha... I have more question about C/C++,do I? Haha... There is another question that can I use Visual C++ to create my DLL files and use it in the Visual C++?
Thanks a lot!!
I want to become programmer!!!
|
|
|
|
|
Do you use ATL or MFC?
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Sorry, I am a new one.
Now, I have learned Visual Basic 6 by myself. And I have learned C.
I want to use Visual C++/C# in furture. So I should learn them verg good new!
Thanks
I want to become programmer!!!
|
|
|
|
|
So if you are beginner put your email here,then I'll send you some document to write dll with MFC and use it.
Also this is very good book
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Hi, my good friend. Thanks for replying my question. And you know I am a beginner. So I don't know how can I improve my programme level. You know, in china, computer is not populer.
And the computer is very expensive in China. So Chinese software is do not famous in the world. So can you tell me what can do improve my programme skill? And what kinds of books I should read?
OK! finally, Thanks a lot.
And this is my E-mail address: alpha_8848_prince@hotmail.com
I want to become programmer!!!
|
|
|
|
|
Hi:
Its good to begin from some online books,I wanted to email them to you but all of them become
too large,so I put their link here and you can download them.You can read one or two of them,then
begin to practice,and here,codeproject,is best place to solve your problems,and also find
lots of tips,sample code and ...You can read them and use them in your programs,and then
you will improve step by step.
My suggestion is after reading one of these books,focus on one field,for example database or user interface or ATL.
Here are the links:
http://http://pcbook.51soft.com/ebooks/english.asp
http://www.amazon.com/exec/obidos/ASIN/0672313502/qid=990742038/sr=1-4/ref=sc_b_4/104-1480260-9675169
http://cplus.h1.ru/cplus/tus/ind.htm
http://tikitak.narod.ru/using/index.htm
http://www.webgeordie.co.uk/visualcpp/database/home.htm
If you need any other helps you are welcome
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Hi, thanks a lot. My good friend.
The words below were have nothing about my question...
Wonderful Programme. Programme is art. How do think about it?
Here, i wanna know how foreigner think about Chinese software. Is there any Chinese software in U.K's or U.S.A's market? (C:
I want to become programmer!!!
|
|
|
|
|
Alpha Intelligence wrote:
Wonderful Programme. Programme is art.
I completly agree with you I love programming too,specially programming with VC. That's a wonderful world,there is nothing and you have some limited tools,then you have to create something new
Alpha Intelligence wrote:
Here, i wanna know how foreigner think about Chinese software. Is there any Chinese software in U.K's or U.S.A's market?
Sorry,I live in Iran and I'm not aware of U.K or U.S.A,and I haven't seen any Chinese program in my country,maybe there are some,but I don't know if they are from China or not.
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Oh, I see. I think I should improve my programme level at once. I love my motherland. So I think I can Change the world! (c:
I want to become programmer!!!
|
|
|
|
|
Alpha Intelligence wrote:
And can I use Visual C++ to write C code
Simply name your file with a .c extension rather than .cpp, and DevStudio will use a C compiler in order to compile that file. You will need to be careful if you are trying to mix C compiled code with C++ compiled code however, because the C++ compiler will mangle the linker symbols in order to make function overloading possible.
|
|
|
|
|
Hi,
This must be really simple, but I am struggling with this. If I have a string such as:
TCHAR hex[] = "0AF79E00";
How can I convert this into a long variable so I know it means:
184,000,000
Is this possible?
Thanks in advance,
Simon
|
|
|
|
|
There are some articles in CP about it.
Check this and this
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|