|
What output were you expecting from your function? Compare that output to the actual output, how do they differ?
|
|
|
|
|
The function is just ensuring that the bytes are in little-endian order no matter what processor
it's running on.
On an x86 machine you could just do this
string
DWORDToString(DWORD dword)
{
string str = "1234";
*((DWORD*)(&str[0])) = dword;
return str;
}
but it wouldn't be the same on a processor that stores 32-bit integers in big-endian order.
The function
Takes the low-order 8 bits and puts it at index 0 position in the array
Takes the next highest order 8 bits and puts it at index 1 position in the array
Takes the next highest order 8 bits and puts it at index 2 position in the array
Takes the highest order 8 bits and puts it at index 3 position in the array
I don't know if this was a typo but
1 0000 0000 Right shift >> 16 gives 0000 0000 0000 0001
is wrong. Should be
1 0000 0000 Right shift >> 16 gives 0000 0000 0000 0000
1 0000 0000 Right shift >> 24 gives 0000 0000 0000 0000
|
|
|
|
|
I don't know if this was a typo but
1 0000 0000 Right shift >> 16 gives 0000 0000 0000 0001
is wrong. Should be
1 0000 0000 Right shift >> 16 gives 0000 0000 0000 0000
1 0000 0000 Right shift >> 24 gives 0000 0000 0000 0000
I think I may have confused you with the way I have written it. I haven't shown them as falling off the end. If you look at where I use the AND function they are represented exactly as you have stated above. Sorry about the confusion. I've tried to clear it up in the original post.
So can someone tell me what the final str would output would be? I'm unable to run the whole program due to certain hardware restrictions so I've created a little test piece of code to view the final result. I get the following
Output str[0]=
Output str[1]=☺
Output str[2]=
Output str[3]=
Str =
The trouble is I then want to concatenate this final str to another string later on but I don't know what str actually is. Is it 0x00010000? But this is in hex should it not be as a char?
|
|
|
|
|
Monk111 wrote: I haven't shown them as falling off the end
Why? They are gone. Why would you leave the 1 on the end and then say ANDing it with 0xFF will
give a result of 0x00?
Anyway...
The final string -
You call the function with dword == 256 (0x00000100)
The resulting str would be str[0] == 0x00, str[1] == 0x01, str[2] == 0x00, str[3] == 0x00
Say you called the function with dword == 0x01020304
The resulting str would be str[0] == 0x04, str[1] == 0x03, str[2] == 0x02, str[3] == 0x01
These aren't ASCII characters so you can't assume you can safely concatenate using a regular
string function. The resulting "string" is just an array of binary bytes (octets) representing
the dword in "little-endian" order. This would be useful if you are writing the bytes in order
across a network so the other end can reassemble them back in to a DWORD regardless of what type
processor is running.
Are you trying to convert a DWORD to a readable ASCII string?
Mark
|
|
|
|
|
Contact me if you can help in making this project come to reality. I would like to get it done as soon as possible but also hope not to pay more than $8K for some top programming for IP Camera software. Is this possible? Am I crazy? I may even entertain a share for the programmer in the Business I am starting.:->
|
|
|
|
|
|
Delicously evil
|
|
|
|
|
You are SO mean, dude...
Windows Calculator told me I will die at 28.
|
|
|
|
|
toxcct wrote: XML pretty Print
toxcct wrote: This[^] is not a regular way to ask for something.
he he he
"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
|
|
|
|
|
Dear All,
I am not sure whether I should post this question in this forum.
If not please let me know the correct forum to post the question.
I am using CPPUnit::XmlOutputter to write the unit test results to an XML file.
The program works as expected and I can see the test results in the xml file.
But I also want to add intermediate results and user defined messages in the same xml result file.
How do I do that?
Thanks a ton,
Arti gujare
|
|
|
|
|
Well I won't say that it's the wrong forum but you might have better luck asking in the CPPUnit forums on sourceforge. Not that you won't get an answer here but you are more likely to get a correct answer there.
|
|
|
|
|
Thank you Wes Aday. I will post it there too.
|
|
|
|
|
Can someone give me a simple example of accessing and sending a image to a picture box control at run time??
Jerry
|
|
|
|
|
Try the .Net Framework[^] board.
There's an example in the PictureBox class overview in the docs.
Mark
|
|
|
|
|
Actually I want to use a Picture Control.
Jerry
|
|
|
|
|
Picture Box? what do you need?
|
|
|
|
|
What the function use for get handle of child windows.
|
|
|
|
|
You could use either:
EnumChildWindows()
or
HWND hChildWindow = GetWindow(hThisHWnd, GW_CHILD);
Darka [ Xanya]
"I am not a slave to a god that doesn't exist."
|
|
|
|
|
If you know the ID of the child you can use GetDlgItem . It works for any window, not just dialogs.
Steve
|
|
|
|
|
Hi,
void C1View::OnViewIncomeview()
{
AfxGetMainWnd()->SendMessage(WM_COMMAND, ID_FILE_NEW);
CMDIFrameWnd *pFrame =
(CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild =
(CMDIChildWnd *) pFrame->GetActiveFrame();
CView *pView = (CView *) pChild->GetActiveView();
CEdit *r1 = new CEdit;
r1->Create(WS_CHILD|WS_VISIBLE|ES_AUTOVSCROLL,
CRect(x1,y1,x2,y2), pView, 1);
CEdit *r2 = new CEdit;
r2->Create(WS_CHILD|WS_VISIBLE|ES_AUTOVSCROLL,
CRect(x3,y3,x4,y4), pView, 1);
r1->SetFocus();
}
I have this piece of code in a function of a called by the application when an icon is clicked on the toolbar.
Now if I go to some other function of the same class and that function moves the caret from one edit box to another
What has to be done?
Thanks
Prithaa
|
|
|
|
|
Hi all,
Could someone please help me with the following problem:
How can I wait for a acknowledgement from another device when I have sent it a piece of data throught the serial port. (before sending the next piece of data).
I'm using VS2K5, and I have done the following:
<br />
..... looping .....<br />
array<String^>^ Text = gcnew array<String^>(10000);<br />
<br />
if (!serialPort1->IsOpen){ <br />
serialPort1->PortName = portNum; <br />
serialPort1->BaudRate = 9600;<br />
serialPort1->Open();<br />
}<br />
<br />
serialPort1->Write(Text[x]);<br />
<br />
:confused: ..... wait for ack ..... :confused:<br />
<br />
array<wchar_t>^ buffer = gcnew array<wchar_t>(10000);<br />
serialPort1->Read(buffer,x,sizeof(buffer));<br />
Thank you in advance
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
You can set a timeout for the reading: you'll wait until either all the data arrived or the timeout expired.
Check out the SetCommTimeout[^] function and the COMMTIMEOUT[^] structure.
|
|
|
|
|
Thanx Cedric ... I'll have a look
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
hi all,
I am having non-blocking TCP socket, trying to receive in a loop for requried bytes.
I am disconnectiing server by removing n/w cable from m/c running server application.
every time recv() fails with WSAWOULDBLOCK, why?
How can i detect that server died abnormally at client end?
recv() also not returning 0?
following is code
iMode = 1; // non-zero = non-blocking mode
iResult = ioctlsocket(sockMain,FIONBIO,(u_long FAR*)&iMode);
iDataGot=0;
while ( iData2Recv >= iDataGot )
{
// recv single byte at a time
iResult = recv(sockMain,&chData,1,0);
// if zero byte got or any other error
if ( iResult == 0 )
{
//never reach here
break;
}
/* timeout scheme
// check timeout period
DWORD dwCur = GetTickCount();
if ( dwCur > dwTimeout )
{
// timeout occured, so we failed
break;
}
*/
if ( iResult == SOCKET_ERROR )
{
if ( WSAGetLastError() != WSAEWOULDBLOCK )
{
// never reaches here
break;
}
else
{
// always executed.
continue;
}
}
// we got something add into output string
if ( iResult == 1 )
{
// add data,update counter into string and break if all datalen is received.
}
client application calls receive() after 10sec and it timeouts after 10sec if no data arrived. I want eliminate later 10sec. and detect server has died.
Thanks in advance.
Jetli
Constant Thing In World Is Change.
|
|
|
|
|
Hi,
Can VC++ work with Linux or Unix?
Or VC++ works only with Winodws?
Prithaa
|
|
|
|