Click here to Skip to main content
15,887,683 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: VC 2005 compiler error Pin
Cedric Moonen28-Nov-07 1:47
Cedric Moonen28-Nov-07 1:47 
GeneralRe: VC 2005 compiler error Pin
neha.agarwal2728-Nov-07 17:36
neha.agarwal2728-Nov-07 17:36 
GeneralRe: VC 2005 compiler error Pin
David Crow29-Nov-07 2:51
David Crow29-Nov-07 2:51 
QuestionHelp with a couple of C questions Pin
3alawii27-Nov-07 23:57
3alawii27-Nov-07 23:57 
AnswerRe: Help with a couple of C questions Pin
manish.patel28-Nov-07 1:31
manish.patel28-Nov-07 1:31 
AnswerRe: Help with a couple of C questions Pin
manish.patel28-Nov-07 1:36
manish.patel28-Nov-07 1:36 
AnswerRe: Help with a couple of C questions Pin
David Crow28-Nov-07 3:26
David Crow28-Nov-07 3:26 
AnswerRe: Help with a couple of C questions Pin
BadKarma28-Nov-07 3:36
BadKarma28-Nov-07 3:36 
This should get you on the way for your second question:

the union:
union AllTypes
{
  signed short    ssData;
  unsigned short  usData;
  signed long     slData;
  unsigned long   ulData;
  float           flData;
  double          dblData;
  unsigned char   ucData[8];
};


the display function:
void doPrint(unsigned char* pData, size_t tCount)
{
  printf("data: ");
  for(size_t tFoo = 0; tFoo < tCount; ++tFoo)
  {
    printf("%d ", pData[tFoo]);
    /* to show the hex values of the byte use:
       printf("%02x ", pData[tFoo]);*/
  }  
  printf("\n");
}


the Swap funtions:
/* I always use 2 functions to preform a swap
  one function for 2 bytes (short), and one to swap 4 bytes (long)*/

void doShortSwap(unsigned short* pData)
{
  unsigned short usTemp = 0xFF & *pData;
  
  usTemp <<= 8;
  *pData >>= 8;
  *pData |= usTemp;
}

void doLongSwap(unsigned long* pData)
{
  unsigned long ulTemp = 0xFFFF & *pData;

  doShortSwap((unsigned short*)&ulTemp);
  ulTemp <<= 16;

  *pData >>= 16;
  doShortSwap((unsigned short*)pData);

  *pData |= ulTemp;
}


and an simple example:
<code>int main()
{
  AllTypes var1;
  
  var1.ulData = 12345687;
  doPrint(var1.ucData, sizeof(AllTypes));

  doLongSwap(&var1.ulData);
  doPrint(var1.ucData, sizeof(AllTypes));

  return 0;
}</code>


codito ergo sum

Questionnfo Pin
john563227-Nov-07 23:24
john563227-Nov-07 23:24 
AnswerRe: nfo Pin
toxcct27-Nov-07 23:28
toxcct27-Nov-07 23:28 
GeneralOfftopic Pin
Nelek28-Nov-07 3:13
protectorNelek28-Nov-07 3:13 
GeneralRe: Offtopic Pin
toxcct28-Nov-07 3:18
toxcct28-Nov-07 3:18 
GeneralRe: Offtopic Pin
Nelek28-Nov-07 21:43
protectorNelek28-Nov-07 21:43 
GeneralRe: Offtopic Pin
toxcct28-Nov-07 21:47
toxcct28-Nov-07 21:47 
QuestionConsult the issue of Win API routine address and code injection Pin
Jude Deng27-Nov-07 23:04
Jude Deng27-Nov-07 23:04 
AnswerRe: Consult the issue of Win API routine address and code injection [modified] Pin
maciu202028-Nov-07 0:20
maciu202028-Nov-07 0:20 
GeneralRe: Consult the issue of Win API routine address and code injection Pin
Jude Deng28-Nov-07 14:48
Jude Deng28-Nov-07 14:48 
GeneralRe: Consult the issue of Win API routine address and code injection Pin
maciu202028-Nov-07 23:15
maciu202028-Nov-07 23:15 
QuestionRe: Consult the issue of Win API routine address and code injection Pin
David Crow29-Nov-07 2:43
David Crow29-Nov-07 2:43 
AnswerRe: Consult the issue of Win API routine address and code injection Pin
maciu202029-Nov-07 9:47
maciu202029-Nov-07 9:47 
AnswerRe: Consult the issue of Win API routine address and code injection Pin
Jude Deng29-Nov-07 13:26
Jude Deng29-Nov-07 13:26 
QuestionRe: Consult the issue of Win API routine address and code injection Pin
David Crow30-Nov-07 2:40
David Crow30-Nov-07 2:40 
QuestionOpening and reading XML files in MFC (C++) Pin
MrFloyd200927-Nov-07 23:01
MrFloyd200927-Nov-07 23:01 
AnswerRe: Opening and reading XML files in MFC (C++) Pin
toxcct27-Nov-07 23:06
toxcct27-Nov-07 23:06 
GeneralRe: Opening and reading XML files in MFC (C++) Pin
MrFloyd200927-Nov-07 23:26
MrFloyd200927-Nov-07 23:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.