Click here to Skip to main content
15,895,283 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CString question - urgent Pin
PJ Arends24-Apr-05 9:04
professionalPJ Arends24-Apr-05 9:04 
GeneralRe: CString question - urgent Pin
hithesh24-Apr-05 9:39
hithesh24-Apr-05 9:39 
GeneralRe: CString question - urgent Pin
Maximilien24-Apr-05 11:19
Maximilien24-Apr-05 11:19 
GeneralRe: CString question - urgent Pin
hithesh24-Apr-05 15:44
hithesh24-Apr-05 15:44 
GeneralRe: CString question - urgent Pin
ThatsAlok24-Apr-05 18:59
ThatsAlok24-Apr-05 18:59 
GeneralRe: CString question - urgent Pin
toxcct24-Apr-05 20:44
toxcct24-Apr-05 20:44 
GeneralText Object Model Pin
Jim Crafton24-Apr-05 8:57
Jim Crafton24-Apr-05 8:57 
GeneralStructions in Windows Pin
Grahamfff24-Apr-05 8:52
Grahamfff24-Apr-05 8:52 
I have a series of structures overlayed with a buffer (fields and buffer of a message). This is in shared memory
Can someone tell me why the first method I use to set fields in a message do not work correctly.
Setting the time tag causes the year data to be wrong - data seems to be 8 bytes wide, even if you cast it to unsigned short.

// Each bit in the 64 byte message is defined in the structure (even spares etc)<br />
typedef struct{<br />
	unsigned long	Msg001_02_01_spare1_w01	:	2;<br />
	unsigned long	Msg001_02_01_msg_code_valid	:	1;<br />
	unsigned long	Msg001_02_01_msg_status	:	1;<br />
	unsigned long	Msg001_02_01_spare2_w01	:	4;<br />
	unsigned long	Msg001_02_01_spare3_w01	:	8;<br />
	unsigned short	Msg001_02_02_time_time_tag;<br />
	unsigned long	Msg001_02_03_year_1000_s	:	4;<br />
	unsigned long	Msg001_02_03_year_100_s	:	4;<br />
	unsigned long	Msg001_02_03_year_10_s	:	4;<br />
	unsigned long	Msg001_02_03_year_1_s	:	4;<br />
	unsigned long	Msg001_02_04_day_10_s	:	4;<br />
	unsigned long	Msg001_02_04_day_1_s	:	4;<br />
	unsigned long	Msg001_02_04_month_10_s	:	4;<br />
	unsigned long	Msg001_02_04_month_1_s	:	4;<br />
	unsigned long	Msg001_02_05_hour_10s	:	4;<br />
	unsigned long	Msg001_02_05_hour_1s	:	4;<br />
	unsigned long	Msg001_02_05_minute_10s	:	4;<br />
	unsigned long	Msg001_02_05_minute_1s	:	4;<br />
	unsigned long	Msg001_02_06_second_10s	:	4;<br />
	unsigned long	Msg001_02_06_second_1s	:	4;<br />
	unsigned long	Msg001_02_06_second_0_1s	:	4;<br />
	unsigned long	Msg001_02_06_second_0_01s	:	4;<br />
}Msg001_02;<br />
<br />
struct TSharedMemory {<br />
	// Form a union between the message structure and a buffer<br />
	union<br />
	{<br />
	    Msg001_02    	     fields;	// Fields in message<br />
	    unsigned short     buffer[32];	// Message buffer use in the Send/Recv etc<br />
	}Msg001_02;<br />
<br />
	etc ...<br />
};<br />
<br />
TSharedMemory	*g_pRigMem;		// Pointer to shared memory object<br />
<br />
		etc ..


If I use the following code to set the time tag it affects the year data:-

g_pRigMem->Msg001_02.fields.Msg001_02_02_time_time_tag = (unsigned short)timeMilseconds;

Even the following does the same:-

g_pRigMem->Msg001_02.buffer[1] = (unsigned short)timeMilseconds;

also the following code seems to do the same for fields in the next word?

g_pRigMem->Msg001_02.fields.Msg001_02_03_year_1000_s = year1000s;<br />
g_pRigMem->Msg001_02.fields.Msg001_02_03_year_100_s = year100s;<br />
g_pRigMem->Msg001_02.fields.Msg001_02_03_year_10_s = year10s;<br />
g_pRigMem->Msg001_02.fields.Msg001_02_03_year_1_s = year1s;


If however I set the void* to the location of the data in the shared memory and use the following code it works OK
// Set the void pointer up (fieldptr)<br />
<br />
if(m_sFieldType == "unsigned short")<br />
{<br />
	*(unsigned short *) fieldPtr = (unsigned short)(timeMilseconds);<br />
}


and for bit fields:-
// Set up the pointer to the byte that holds the field first<br />
<br />
*(char *) fieldPtr = (char)(bitField);


This sets the data OK and the years data is OK.

Can someone explain why the first method causes the problem.

Many thanks,

Graham.


grahamfff
GeneralRe: Structions in Windows Pin
PJ Arends24-Apr-05 9:18
professionalPJ Arends24-Apr-05 9:18 
GeneralCompression Pin
_Jackie24-Apr-05 8:16
_Jackie24-Apr-05 8:16 
GeneralRe: Compression Pin
John M. Drescher24-Apr-05 9:20
John M. Drescher24-Apr-05 9:20 
GeneralRe: Compression Pin
PJ Arends24-Apr-05 9:21
professionalPJ Arends24-Apr-05 9:21 
Generalvc++ progamming for multimedia Pin
ahmadmz24-Apr-05 7:35
ahmadmz24-Apr-05 7:35 
GeneralPlease Help me, Excel Automation with MFC Pin
lee kyu sub24-Apr-05 6:27
lee kyu sub24-Apr-05 6:27 
Generalhelp me about Explorer-like program Pin
NPDemon24-Apr-05 5:59
NPDemon24-Apr-05 5:59 
GeneralRe: help me about Explorer-like program Pin
Ravi Bhavnani24-Apr-05 7:40
professionalRavi Bhavnani24-Apr-05 7:40 
GeneralRe: help me about Explorer-like program Pin
NPDemon29-Apr-05 8:45
NPDemon29-Apr-05 8:45 
GeneralCString to binary Pin
Lampros Giampouras24-Apr-05 5:20
Lampros Giampouras24-Apr-05 5:20 
GeneralRe: CString to binary Pin
Ravi Bhavnani24-Apr-05 7:43
professionalRavi Bhavnani24-Apr-05 7:43 
GeneralRe: CString to binary Pin
Lampros Giampouras24-Apr-05 9:27
Lampros Giampouras24-Apr-05 9:27 
GeneralAPI Hooking question Pin
olinn24-Apr-05 4:40
olinn24-Apr-05 4:40 
QuestionHow to SetDocumentHtml to HtmlEditCtrl Pin
Tcpip200524-Apr-05 2:16
Tcpip200524-Apr-05 2:16 
AnswerRe: How to SetDocumentHtml to HtmlEditCtrl Pin
22491724-Apr-05 4:34
22491724-Apr-05 4:34 
GeneralRe: How to SetDocumentHtml to HtmlEditCtrl Pin
Tcpip200524-Apr-05 23:42
Tcpip200524-Apr-05 23:42 
Generalstructs and arrays Pin
Truby4224-Apr-05 1:34
Truby4224-Apr-05 1:34 

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.