|
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.
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 />
union<br />
{<br />
Msg001_02 fields;
unsigned short buffer[32];
}Msg001_02;<br />
<br />
etc ...<br />
};<br />
<br />
TSharedMemory *g_pRigMem;
<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
<br />
if(m_sFieldType == "unsigned short")<br />
{<br />
*(unsigned short *) fieldPtr = (unsigned short)(timeMilseconds);<br />
}
and for bit fields:-
<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
|
|
|
|
|
Grahamfff wrote:
unsigned long Msg001_02_01_spare3_w01 : 8;
unsigned short Msg001_02_02_time_time_tag;
unsigned long Msg001_02_03_year_1000_s : 4;
I would make the time tag the same format as the rest
unsigned long Msg001_02_02_time_time_tag : 16;
Maybe also pack the structure and union to 1 byte boundaries using #pragma pack(1) . You could be running into alignment problems.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
Hi, i need for my final project to make a software that compress file, but i don't know where to start , if someone know something about this, pls help me, i need it.
thanks
Jackie.
|
|
|
|
|
You need to start by figuring out what algorithm you want/need to use. Huffman, LZW ... Then you can search this site for examples. Then if you do not find what you need there is always google.
John
|
|
|
|
|
|
why we use vc++ to programing multimedia player
|
|
|
|
|
(VC6.0, Excel 2000)
Range range;
Borders borders;
range = sheet.GetRange(COleVariant("A1"), COleVariant("L6"));
borders = range.GetBorders();
borders.SetLineStyle(COleVariant((short)1));
This sample is applied to all cells ..
but I want only outline
plese help me.... I want reference source...
|
|
|
|
|
i want to program a dialog-based program,which contains a CListCtrl ,i want the CListCtrl to act like MS ExPlorer
but i don't know how to do it.
someone can tell me how to do it ,or tell me this is about what subject,best some relative articles ?
thanks
|
|
|
|
|
|
|
I need to convert CString to binary and back. Does anyone know how?
|
|
|
|
|
What do you mean by "convert a CString to binary and back"?
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
CString: "Hello there" -> Binary: 1001110100101001.....
I want to take each bit of that and put it in some image pixels for watermarking..
|
|
|
|
|
I want to hook some APIs. I has some questions when reading the article on codeproject website
http://www.codeproject.com/dll/apihijack.asp[^]
The sample in that article is to hook DirectDrawCreate function in DDRAW.dll, and change it with his own function in his own dll. I am just wondering why he set a global WH_CBT hook but with a callback function doing nothing (just do CallNextHookEx).
When I made some mouse hook or keyborad hook, I always did my work in the callback function, so I am confused that why we changed when do API hooking.
Thanks in advance!
|
|
|
|
|
I used SetDocumentHtml to set my html code to the HtmlEditCtrl.
but It's no use.
Why was this happen?
How can I set html document to htmleditctrl??
Thank you very much!!!
|
|
|
|
|
I feel you got to check CHtmlEditCtrlBase::SetDesignMode().
suhredayan There is no spoon.
|
|
|
|
|
Thank you!
Yes , I got a way to do this.
But,when I set html document for htmleditctrl,the resources(jpg,gif etc.) can't be showed .
Only text can be showed.
what's the matter??
|
|
|
|
|
I am a beginner taking my first programming class so answer at my level I have a struct
struct stats
{
int score;
int frequency;
}
stats gradebook[10];
now I want to read this info into the array of structs from a file called scores.txt how do I set up the function getscores and read in from the file
|
|
|
|
|
See fopen() , fscanf() and fclose() .
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
hello friends
i want to use some functions in my project please tell me from which functions i can get these value in LAN
cpu usage
available network bandwidth
network packets per second
memory usage
thanx
bye
|
|
|
|
|
hiho@ll
a question to all hardcore (windows) C++ hackers
if i have a few thousand (or many many more) objects, how could i have access to each object indivdually and (extremly) very fast?
i thought about using collections but i thinkg that it would be very slow if there are a many 10000 objects which i need to access
and how i have access to all of them without waiting for a thread to finish
i mean how could i synchronize the access to those objects if i'm running many threads, but i don't want a thread to wait for it's information because it would slow down?
thx@ll
|
|
|
|
|
Use hash! It's as short as that. There are many classes available, from Micro$oft, Boost, etc.. Those are fast enough to handle hundreds of thousands entries.
Greetz, pat le hashed :->
|
|
|
|
|
|
hiho@ll
i'm thinking about a project, which would need a few thousands threads running and every thread should be accessible everytime (i think about a vector or something else in the core)
so my question, what is the maximum number of threads/Objects windows/VC can produce/handle?
am i right that, it should be depeding on how much RAM i have and not on somthing different?
thx@ll
|
|
|
|
|
How is the vector related to the multiple threads?
Are you trying to access the same vector from multiple threads?
Top ten member of C++ Expert Exchange.
http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/
|
|
|
|