|
Sorry it should be char tempBuff[1024]
I appreciate your help all the time...
Eranga
|
|
|
|
|
char tempBuff[1024];
unsigned int iReq;
char newBuff[1024 + sizeof(iReq)];
memcpy(newBuff, &iReq, sizeof(iReq));
memcpy(newBuff + sizeof(iReq), tempBuff, 1024);
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
TO CPallini:
Then how to read the first four bytes out to form the int value?
<br />
char tempBuff[1024];<br />
unsigned int iReq;
char newBuff[1024 + sizeof(iReq)];<br />
memcpy(newBuff, &iReq, sizeof(iReq));<br />
memcpy(newBuff + sizeof(iReq), tempBuff, 1024);
Can this achieve?
<br />
int *iptr = &newBuff[0];<br />
int iTReq = *iptr;
|
|
|
|
|
fantasy1215 wrote: Can this achieve?
int *iptr = &newBuff[0];
int iTReq = *iptr;
Yes.
Maxwell Chen
|
|
|
|
|
The code is correct, provided you cast the pointer, i.e.
int *iptr = (int*) (&newBuff[0]);
int iTReq = *iptr;
you can also do directly
int iTReq = *((int*)(&newBuff[0]);
or
int iTReq = *((int*)newBuff);
Cheers
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Hello friends,
I want to delete shortcuts that is .lnk files from a particular folder.
some buddy please suggest & give some Sample code for this.
Thanks in advance...
|
|
|
|
|
|
You can delete them just like you would any other file. What extension the file has is unimportant.
"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
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi
In my system not installed languagepack.when i paste chinese characters in rtf ..
In sending i wrote this code...
here m_chattext is rtf object.
m_chattext.GetWindowText(m_Text);
AfxMessageBox(m_Text);
in messagebox the chinese characters are not displaying..its coming ???? how i can solve this problem ...plz tell...
#sanroop#
|
|
|
|
|
do you have compiled your project as unicode ?
if not, make sure that you use
preprocessor definitions ( c++ page )
_UNICODE
output (link page) - entry point symbol
wWinMainCRTStartup
further on you could use _T("") instead "" in your code
hope it helps
|
|
|
|
|
no sir its not coming....
#sanroop#
|
|
|
|
|
i think you are correct
perhaps you could use CEdit instead but if not keep in mind
RichEditCtrl in Visual C++ 7.0 supports Unicode. To obtain Unicode strings from the RichEditCtrl box, use EM_GETTEXTEX message instead of GetDlgItemText.
SendMessage(
EM_GETTEXTEX,
(LPARAM) &getTextEx, // GETTEXTEX structure
(WPARAM) lpszWChar // output WCHAR array
);
see also:
http://easai.00freehost.com/unicode.html[^]
|
|
|
|
|
Hi friends,
I am trying to allocate around 3 sets of nearly 1.8MB of memory with calloc inside OnInitDialog() function of MFC. I used a memory leak detector tool and before I could start the worker threads I was able to see memory leaks in the lines which I used to allocate the memory mentioned above. Is there any issue in using calloc for memory allocation more than 64KB. I am using Win2000 with Visual studio 6.0 (VC++).
Following is the code snippet I used.
char *source_buf;
unsigned long size = 9001;
source_buf = (char*) calloc((size*200),sizeof(char));
|
|
|
|
|
Does your application check calloc return value?
Does it free allocated memory?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
I am not checking calloc value. But in debug mode I have watched the pointers. They are valid ones. At the same time I would like to mention that I am not freeing them anywhere in the code because this buffer is used cyclically throughout the runtime of the code by the worker thread. The pointer is duplicated for use by the worker thread.
char *store_buf;
store_buf=source_buf;
|
|
|
|
|
Since you are using MFC, why are you avoiding the new operator?
"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
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I am a bit curious about why to use new in MFC. What is the danger which is avoided by using 'new' and why such a precaution in MFC. I am almost unaware about MFC and its fundamentals.. That's why I am curious about the above issue
|
|
|
|
|
For integral types, there's not much difference other than the ability to track down memory leaks. For classes/objects, the new operator will also call the constructor.
"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
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks for the valuable information
|
|
|
|
|
I created a context menu and displayed it using TrackPopupMenu . I do not use TPM_RETURNCMD . My application window receives the result of user selection.
It works fine if I select/click some menu item - the window receives message for the given menu item. However if I cancel the context menu (hit Esc or click somewhere else) I do not receive any message. Is there any mechanism to catch context menu cancel event?
Another question, how to determine if a context menu (CMenu) is active and displayed?
Thanks,
Abyss
|
|
|
|
|
TrackPopupMenu will return 0 if user cancels the menu.
Abyss wrote: Another question, how to determine if a context menu (CMenu) is active and displayed?
If you call the TrackPopupMenu, the thread is blocked at that statement as long as the menu is displayed. So from where you want to know the state of menu?
|
|
|
|
|
If I call TrackPopupMenu with TPM_RETURNCMD flag then the thread is blocked and I can check the return value. However I do not use the TPM_RETURNCMD flag which cause that the TrackPopupMenu creates the context menu and immediately exits. The menu is still active and sending messages to the window. That is why I can't check the return flag because it just say that the menu has been created.
Abyss
|
|
|
|
|
Abyss wrote: If I call TrackPopupMenu with TPM_RETURNCMD flag then the thread is blocked and I can check the return value
I dont think so. please try putting a messagebox in the next line after the TrackPopupMenu() and see whether it is coming or not.
|
|
|
|
|
Uff, you are right. I put a breakpoint right after the TrackPopupMenu call and it returned only after the menu was closed. Meanwhile the WinAPI send notification to the window.
I do not understand why I did not try this?!
Many thanks,
Abyss
|
|
|
|
|
Naveen wrote: TrackPopupMenu will return 0 if user cancels the menu.
Only if the TPM_RETURNCMD is specified. If not it will return the success or failure status.
See the MSDN documentaion.
If you specify TPM_RETURNCMD in the fuFlags parameter, the return value is the menu-item identifier of the item that the user selected. If the user cancels the menu without making a selection, or if an error occurs, then the return value is 0.
If you do not specify TPM_RETURNCMD in the fuFlags parameter, the return value is nonzero if the function succeeds and 0 if it fails. To get extended error information, call GetLastError.
|
|
|
|