|
unsigned char bArray[sizeof(double)];
double d;
memcpy(bArray,&d, sizeof(double));
reverse:
memcpy(&d, bArray, sizeof(double));
|
|
|
|
|
kakan wrote: unsigned char bArray[sizeof(double)];
won't compile. you have to do it this way :
unsigned char* bArray = new unsigned char[sizeof(double)];
which is why i directly put [8] to ease the code (standard C++ tell that the size of a double is fixed to 8 bytes, so doesn't vary).
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VisualCalc 3.0]
|
|
|
|
|
Hello.
You are right (of course).
But the memcpy is neat, isn't it?
|
|
|
|
|
|
Thanks.
|
|
|
|
|
Actually you are incorrect. sizeof(double) is a compile time constant, and so it will compile. (Just to double check, I tried and it did.)
|
|
|
|
|
Obviously the best wat to do this is to not do it, viz:
union MyConvert
{
double d;
BYTE bytes[sizeof(double)];
};
Thus for some function storeBytes(BYTE*p, size_t size)
to get a double called myVal stored do this:
MyConvert mc;
mc.d = myVal;
storeBytes(mc.bytes, sizeof(myVal);
or if you want to go nuts and save the copy:
storeBytes(((MyConvert*)(&myVal))->bytes, sizeof(myVal));
Though that might not work if the alignment requirements are different between double and unions.
|
|
|
|
|
Hi,
Could someone point me to the problem.
When I use this:
<br />
m_Edit.SetWindowText(str+"W");<br />
I get one "W" character displayed before str and two displayed after.
If str is "----------", I get "W----------WW".
Thank you,
|
|
|
|
|
Does SetWindowText take a CString? I dont know where that SetWindowText comes from, but I will just assume it takes a LPSTR* or a const char*. In that case, you need to make sure that SetWindowText gets what it needs. I am not familiar with CString, but I suspect that (as of now) it is an alias for std::string? In that case, try
<br />
str += W;<br />
m_Edit.SetWindowText(str.c_str());<br />
Cheers
Seb
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
Try to construct the CString before passing it to SetWindowText:
CString Temp = str + "W";<br />
m_Edit.SetWindowText(Temp);
|
|
|
|
|
Is the m_edit box object of CEdit
i tried it and did not get any error
the str was dispalyed ad "---------W"
CString str;<br />
str.Format ("----------");<br />
m_memorystatus.SetWindowText (str+'W');
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
bachirzantou wrote: m_Edit.SetWindowText(str+"W");
CString str =="Whatever text";
str+="W";
m_Edit.SetWindowText(str);
or
m_Edit.SetWindowText(str.GetBuffer(0));
or
m_Edit.SetWindowText(str.operator LPCTSTR());
Happy christmas friends. May the Love of My Lord and Saviour Jesus bring forth Joy and Happiness into your life too.
<marquee direction="up" height="50" scrolldelay="1" step="1" scrollamount="1" hspace="2" vspace="2">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
SetWindowText() is waiting for a CString, so there's no reason for casting back into a C-style string (LPCTSTR).
moreover, when somebody took time to design a cast operator, it should be used properly, in the C style too. so, instead of writing str.operator LPCTSTR() , simply write (LPCTSTR)str
one last thing. when you .GetBuffer() a CString, you should release it then (which you seemed to forget here...)
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VisualCalc 3.0]
|
|
|
|
|
Game over;P
Happy christmas friends. May the Love of My Lord and Saviour Jesus bring forth Joy and Happiness into your life too.
<marquee direction="up" height="50" scrolldelay="1" step="1" scrollamount="1" hspace="2" vspace="2">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
|
toxcct wrote: Owner drawn wrote:
Game over
for you ?
which game are we playing
"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
|
|
|
|
|
|
toxcct wrote: hey, you wrote it, so it's you to tell me man !!
Ringa Ringa Roses
"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
|
|
|
|
|
ThatsAlok wrote: which game are we playing
Break-A-Crack-Brack-Drack-Dreak-Hreak
Happy christmas friends. May the Love of My Lord and Saviour Jesus bring forth Joy and Happiness into your life too.
<marquee direction="up" height="50" scrolldelay="1" step="1" scrollamount="1" hspace="2" vspace="2">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
-- modified at 23:16 Thursday 22nd December, 2005
|
|
|
|
|
Owner drawn wrote: Break-A-Crack-Brack-Drack-Dreak-Hreak
what game is that .... is we are bird
"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
|
|
|
|
|
toxcct wrote: one last thing. when you .GetBuffer() a CString, you should release it then (which you seemed to forget here...)
it should be followed up with a ReleaseBuffer()
toxcct wrote: SetWindowText() is waiting for a CString, so there's no reason for casting back into a C-style string (LPCTSTR).
Yeah you are right.
Happy christmas friends. May the Love of My Lord and Saviour Jesus bring forth Joy and Happiness into your life too.
<marquee direction="up" height="50" scrolldelay="1" step="1" scrollamount="1" hspace="2" vspace="2">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
-- modified at 6:39 Thursday 22nd December, 2005
|
|
|
|
|
The game dont end thill a stable solution is found
Happy christmus
to u also
&
all persons in Codeproject
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
idiot question, but, what about using the debugger to see the state of the variable str before and after the operation ?
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VisualCalc 3.0]
|
|
|
|
|
I'm not sure if it wroks, but you can try this:
m_Edit.SetWindowText((CString) str+"W");
kakan
|
|
|
|
|
kakan wrote: ((CString) str+"W");
Mmmmh... IMO this is no good code practice. Better use the temp variable.
~RaGE();
|
|
|
|