|
The GetTextExtent... functions will do that.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
Hey everybody. Does anybody got a clue why this code doesn't work? I wanted to simply create a string with that number in it, without using sprintf.
void Test (long lSomeValue)<br />
{<br />
char *cValue = (char*)malloc(15);<br />
char *cText = (char*)malloc(50);<br />
<br />
cText = "The number is: ";<br />
_ltoa(lSomeValue, cValue, 10);<br />
strcat(cText, cValue);<br />
MessageBox(0, cText, "bla", 0);
}<br />
Test(10);
So how can I do this without using sprintf? And without using CString class.
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
Axonn Echysttas wrote:
void Test (long lSomeValue)
{
char *cValue = (char*)malloc(15);
char *cText = (char*)malloc(50);
cText and cValue are pointers. Right now they point to the memory locations returned by the malloc function.
Axonn Echysttas wrote:
cText = "The number is: ";
cText now points to a different memory location then it did before. It now points to a static memory containing the text "The number is: ". To actually copy the text into the memory that was allocated with malloc you have to use strcpy()
strcpy (cText, "The number is: ");
Axonn Echysttas wrote:
_ltoa(lSomeValue, cValue, 10);
strcat(cText, cValue);
Here the strcat function will fail, most likely with an access violation, because the memory pointed to by cText is readonly memory.
To see this happen, run the program in the debugger, and step through the Test() function, watching the values of cValue and CText as you go. The debugger will give you the memory address pointed to be the pointers, followed by the text contained in that memory. Note the addresses that are assigned by the malloc calls. Now see how when you call cText = "The Number is: "; the address that cText points to changes well as the text, but when you call _ltoa(lsomevalue, cValue, 10); the address that cValue points to remains the same, but the text at that address changes.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
Thanks PJ Arends. This is the second time you pull me out of my misery : D. This question was actually for an article I'm working on... for the Code Project that is. It's about inter-process communication. I hope in 2 weeks it's gonna be done, since I'm not working at it all the time. Anyway... I understand now the memory issue. I'm not such an expert in these things since I started using Visual C++ recently compared to you guys. I'm gonna post a message here when I uploaded that article. But I wrote to the Code Project staff, since I got a user-name problem (lost my old e-mail) and they didn't answer yet. Until they do even if I finish it I won't be able to upload it.
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
1) Do not allocate the buffers (unless you have to). Not only is this bad programing, I see that you do not free them (memory leaks).
2) You are changing the memory address stored in cText from what you allocated to the address of a static string (consisting of only 17 characters[boom - memory leak]).
void Test(long lSomeValue)
{
char cValue[15];
char cText[50] = "The number is: "; // or {"The number is: "};
strcat(cTest,_ltoa(lSomeValue, cValue, 10));
MessageBox(0, cText, "bla", 0);
}
Note (above): No (C) memory allocations was required (every thing is on the stack). The pointer returned by _ltoa() is a pointer to cValue (no error return), so you can combine the two function calls into one.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Thanks John : ). Looks great.
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
I had finished a program,and I want to change the Icon of it.
I copy and past my icon that I had drew in PhotoShop on the icon-drawer of VC++6.0
But... the icon became 16colors-icon
Not only that...The icon of program under some dir is my icon...
but when i put my program under desktop...
very strange... the Icon of program became the icon of MFC
Why?
So... How to change the icon of program...and make the icon won't change when it was put under desktop?
PS: The icon must to be 32bits and larger than 32*32
Thanks a lots!
|
|
|
|
|
Hi,
try to replace the icons in your 'MyProg\res' folder with the new ones.
And never touch any icon with the icon editor of VC++ 6.0
Regards
|
|
|
|
|
Some icons contain two files:
1 file 16x16 icon ( thats for winExplorer )
2 file 32x32 icon ( for desktop and thumbanail view )
If you define icon with only one file, the other will be replaced with built-in icon. So just create two file icon.
CRPG, FRPG, Oblivion Fan
Hater of Counter Strike ( i hate it soo much damn it );
|
|
|
|
|
I need to get input boxes on html web form, I using IHTMLDocument2
<br />
m_pHtmlDoc->get_body(&m_pBody);<br />
CComPtr<IHTMLElementCollection> pForms;<br />
m_pHtmlDoc->get_forms(&pForms);<br />
long lFormLenght = 0;<br />
pForms->get_length(&lFormLenght);<br />
IDispatch *pDispatch = NULL;<br />
for (int i =0 ; i < lFormLenght; i ++ )<br />
{<br />
VARIANT variant;<br />
variant.lVal = i;<br />
variant.vt = VT_I4;<br />
pForms->item(variant, variant, &pDispatch);<br />
CComPtr<IHTMLFormElement> pForm;<br />
<br />
pDispatch->QueryInterface(IID_IHTMLFormElement,(void**)&pForm);<br />
BSTR bstrTemp;<br />
long lLen = 0;<br />
pForm->get_length(&lLen);<br />
CComPtr<IHTMLElement> pElement;<br />
for (int j = 0; j < lLen; j++ )<br />
{<br />
IDispatch *pDispInput = NULL;<br />
VARIANT varInput = {0};<br />
V_I4(&varInput) = j;<br />
<br />
HRESULT hr = pForm->item(varInput, varInput, &pDispInput);<br />
CComPtr<IHTMLInputElement> pInput;<br />
hr = pDispInput->QueryInterface(IID_IHTMLInputElement, (void**)&pInput);<br />
pInput->get_name(&bstrTemp);<br />
pInput->get_value(&bstrTemp);<br />
BSTR bstrNewValue = L"Hello word";<br />
pInput->put_value(bstrNewValue);<br />
pDispInput->Release();<br />
}<br />
}<br />
in string
<br />
hr = pDispInput->QueryInterface(IID_IHTMLInputElement, (void**)&pInput);<br />
in pInput I get only first input box, but on my form two input boxes.
Why I can't get second input box?
|
|
|
|
|
Im using boZoi library to implement Elliptic curve cryptography to my VC project.The functions output r in the format of hexadecimal and OCTETSTR(octant string) now if i want to show the output in the edit box control of a dialog box...???.
ECDSA sig;
HexEncoder hex(sig);
CEdit* poEdit = static_cast<cedit*>(GetDlgItem(IDC_EDIT3));
poEdit->SetWindowText(hex);
HexEncoder is a class which converts to hexadecimal format & i want to convert it converted to CString or LPCTSTR...How i do that?
borZoi can be found at:
http://dragongate-technologies.com/products.html[^]
|
|
|
|
|
|
Yup it worked fine...thanx.But that converts Octant string to Hex String....here i want to convert Hexadecimal to char* or CString to show in edit box....I dont know if the same method can be applied here?
|
|
|
|
|
OK as u suggested i used ostringstream to store hex vaue as a string and then convert it into a CString form to show in the edit control of dialog box.It gives no error but at the time of execution of this code "illegal operation error" message box is displayed.Where Im doing wrong?
std::string s("");
ECDSA sig1(sk, OS2IP(hash)); // generate the signature
DER der_str (sig1); //DER class function
HexEncoder hex_str(der_str); //Hexencoder class function
std::ostringstream str;
str<<hex_str; storing="" hex="" value="" as="" a="" string
s="str.str();
CString" cs="s.c_str();
CEdit*" poedit="static_cast<CEdit*">(GetDlgItem(IDC_EDIT3));
poEdit->SetWindowText(cs);
|
|
|
|
|
OK as u suggested i used ostringstream to store hex vaue as a string and then convert it into a CString form to show in the edit control of dialog box.It gives no error but at the time of execution of this code "illegal operation error" message box is displayed.Where Im doing wrong?
std::string s("");
ECDSA sig1(sk, OS2IP(hash)); // generate the signature
DER der_str (sig1); //DER class function
HexEncoder hex_str(der_str); //Hexencoder class function
std::ostringstream str;
str<<hex_str; storing="" hex="" value="" as="" a="" string
s="str.str();
CString" cs="s.c_str();
CEdit*" poedit="static_cast(GetDlgItem(IDC_EDIT3));
poEdit-">SetWindowText(cs);
Hope ull reply soon.
|
|
|
|
|
titi@yahoo.com wrote:
It gives no error but at the time of execution of this code "illegal operation error" message box is displayed.Where Im doing wrong?
Hard to tell without knowing at what point in the code you get that error.
In any case, if you looked at the DER declaration in borzoi.h, you'd note DER objects hold their data in an OCTETSTR public member named v , and as I already shown you how to code an OctetStrToHexString , you'd realize you can simply use OctetStrToHexString passing der_str.v .
ECDSA sig1(sk, OS2IP(hash));
DER der_str (sig1);
CWnd* pWnd = GetDlgItem(IDC_EDIT3);
if (pWnd)
{
CString sDer;
OctetStrToHexString(der_str.v, sDer);
pWnd->SetWindowText(sDer);
}
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Thnx for (late) reply but ive done it and through the same method as u told.
Since Im stuck in cryptography stuff nad Im using CryptoAPI Ive some data of type BYTE* (PUBLICKEYBLOB)I want to write it in a file then send it across the network and then read from file and use that public key.SIGH!!!!
now to write it in the file i covert BYTE* to CHAR* and then inverse to read ...but to dont get the same value back.
Do u have any better idea to do this??
Thanx again for ur help.
|
|
|
|
|
How to create multiple toolbars?]
Thanks
|
|
|
|
|
when I am setting any type of hooks within a DLL and I want to print any information in a file from that DLL (for example at what time a WM_xxx message was sent or things like that) my hook callback freezez it just doesn't respond. I am using fopen,fprintf,fclose functions. I know this is the problem because when I use a messagebox for example instead of writting in a file it works fine.
Can someone tell what is the problem. This used to work
Sorry for my english
gabby
|
|
|
|
|
Hi!
I'm just starting COM,and have to submit a project this semester... advanced networking and COM. we are a team of four... Can anyone suggest a good topic for the project... one such that i can show it on my resume... thanks!
|
|
|
|
|
They should of taught you about COM, before teaching you about networking.
(They are totally different subjects)
1) Don't think about the COM part (too much).
2) Write code that can send via the network, as well as receive.
3) Then write a COM wrapper around your code.
The term network does not matter, it is just a place holder, which applies to networking in general.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
hi!
thanks for the advice, but i know about networking..in fact we had developed a FTP client and server earlier this year.. what i wanted was to develop something new.. there are so many networking projects right?
|
|
|
|
|
hiho@ll
i have a prog (already compiled (.exe) and i don't have the source)
i want this prog, which only runs as single instance, to have it run more instances
is this possible?
if yes, how?
i had 2 ideas
both i don't know how to do:
1. change the prog itself, that it can run more instances (well, how?)
2. change some OS settings, if the prog already runs, so that if the program checks if there is already a running instance, the windows tells the prog "no you'r alone" (how?)
thx@ll
|
|
|
|
|
ThinkingPrometheus wrote:
is this possible?
unfortunately yes.
BUTT,
Most people who want to stop multiple instances (of their program), have a good reason for doing so.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
i know there is a reason
but not everytime! sometimes there are progs, which have this feature just to have it
do you know how it works? if yes, how?
thx
|
|
|
|