|
Compilers may not place all members of a struct adjacent to each other; this is called packing. Depending on the CPU architecture, it may be more efficient or even required that memory accesses take place on 2 byte, 4 byte, or higher boundaries. I believe the default packing for Visual C++ is 8 bytes. This means that your struct 's will have padding between the members.
Fortunately, you can override this behavior in your code:
#pragma pack(push,1)
typedef struct {
u_32 prot_ver;
u_32 nomem_ver;
u_32 func_units;
u_32 sysType;
u_32 startupMode;
AttributeList option_list;
AttributeList supported_aprofiles;
} UserInfo;
typedef struct {
u_16 attribute_id;
u_16 length;
u_16 attribute_val;
} AVAType;
typedef struct {
u_16 count;
u_16 length;
AVAType value[1];
} AttributeList;
#pragma pack(pop) The initial pragma saves the current packing level, and then sets it to 1, which will cause all members to be adjacent, with no padding. The final pragma restores the packing level.
Software Zen: delete this;
|
|
|
|
|
I already had the the #pragma statements around my entire h-file and its still happening. Is there another setting for this??
Do I need to explicitly put it around each struct or at the beginnng of the H file sufficient?
I"m pushing and popping in every h-file that has structs defined. Thanks.
-C
|
|
|
|
|
Wheatbread wrote:
already had the the #pragma statements around my entire h-file and its still happening. Is there another setting for this??
There is a default value set using the /Zp command line option to the compiler. You can look in your project settings to see what it is.
Wheatbread wrote:
Do I need to explicitly put it around each struct or at the beginnng of the H file sufficient?
'Around each struct' is not required. The pragma pack(push,1) remains in effect until the corresponding pragma pack(pop) is encountered. Just for the sake of consistency, though, I would put the push and pop in each .H file that needed it. That way, if another .H is included in between that changes the packing level, you don't have unforseen changes taking place.
Software Zen: delete this;
|
|
|
|
|
My project settings are /Zp1. I changed structure alignment to 1 byte when I created the file.
Am I copying the struct wrong maybe? I've done this many times before and this hasnt happened.
Not sure how else to do it other than copying the AttributeList struct inside the larger struct separately, but that would SUCK!
I"ll take all suggestions here!!
-C
|
|
|
|
|
Actually I believe it is called alignment and I believe that the default behavior is to align data to the size of the item. This means a double (8 bytes) is aligned to an 8-byte boundary, four-byte items are aligned to four-byte boundaries, etc.
However, I don't have a good explanation for why the memcpy fails. I recommend inserting some trace messages to display the sizeof values to see if something looks weird. sizeof should take into account alignment issues.
__________________________________________
a two cent stamp short of going postal.
|
|
|
|
|
Print out the sizeof UserInfo. Make sure that value looks good.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
you don't read previous posts do you ?
__________________________________________
a two cent stamp short of going postal.
|
|
|
|
|
I did and at no point what this information discussed.
The problem is that you guys are off in the weeds talking about things that probably have nothing to do with the problem.
Why would memcpy fail?
Why would data be missing?
The truth is memcpy probably isn't failing and the data is missing because it wasn't there to begin with.
Chances are the data coming in isn't good and thus the data coming out is just as bad. The data being such things as the input data and the size of the data block. One of those two are bad.
memcpy doesn't fail unless you give it trash.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
The sizeof (UserInfo) would be interesting.
FWIW I ran your code in a test program and it packs properly,
#pragma pack ( push, 1 )
typedef struct {
unsigned short attribute_id;
unsigned short length;
unsigned short attribute_val;
} AVAType;
typedef struct {
unsigned short count;
unsigned short length;
AVAType value[1];
} AttributeList;
typedef struct {
unsigned prot_ver;
unsigned nomem_ver;
unsigned func_units;
unsigned sysType;
unsigned startupMode;
AttributeList option_list;
AttributeList supported_aprofiles;
} UserInfo;
#pragma pack ( pop )
int main()
{
UserInfo ui ;
ui.prot_ver = 'AAAA' ;
ui.nomem_ver = 'BBBB' ;
ui.func_units = 'CCCC' ;
ui.sysType = 'DDDD' ;
ui.startupMode = 'EEEE' ;
ui.option_list.count = 'FF' ;
ui.option_list.length = 'GG' ;
ui.option_list.value[0].attribute_id = 'HH' ;
ui.option_list.value[0].length = 'II' ;
ui.option_list.value[0].attribute_val = 'JJ' ;
ui.supported_aprofiles.count = 'KK' ;
ui.supported_aprofiles.length = 'LL' ;
ui.supported_aprofiles.value[0].attribute_id = 'MM' ;
ui.supported_aprofiles.value[0].length = 'NN' ;
ui.supported_aprofiles.value[0].attribute_val = 'OO' ;
char * msgBuffer = new char [1000];
::memset ( msgBuffer, 0, 1000 ) ;
::memcpy (msgBuffer, (char *) &ui, sizeof (UserInfo)) ;
std::cout << "UserInfo size = " << sizeof ( UserInfo ) << std::endl ;
std::cout << msgBuffer << std::endl ;
delete [] msgBuffer ;
return 0;
}
Output was
UserInfo size = 40
AAAABBBBCCCCDDDDEEEEFFGGHHIIJJKKLLMMNNOO
However it seems to me that your use of arrays of AVAType in AttributeList implies that they need to be of variable length and therefore this whole problem will be moot?
Paul
|
|
|
|
|
I'm not sure why its not working either.
The AVATypes will be variable length in the result msg that I receive. The transmitted message only have one AVAtype.
I will try checking the size of etc and see what happens and post again. Thanks.
-C
|
|
|
|
|
Please, anybody help me.
I'm a beginner in MFC.
And I'm sorry for my english if it's not good. I'm from Russia.
Now I'm making a simple database program and I'm need to provide a search mechanism for it.
Well, for instance, my general view class is CDBView and search dialog class is CSearch.
Search dialog is called by CDBView::OnSearch() function (Menu item). It's look like this:
CDBView::OnSearch()
{
CSearch dialog;
dialog.DoModal();
...
"search mechanism"
}
But I can't provide "search mechanism" by calling DoModal() in CDBView::OnSearch() and by writing
"search mechanism code" in CSearch::OnOK() (OK is the button for search in dialog). Why??? I've
got "Debug Assertion Failed ..." or something like that. What does this mean?
My search mechanism uses CRecordset m_pSet variable that also defined in CDBView class.
NOTE: search mechanism fully work if defined in CDBView class.
|
|
|
|
|
Jeez - you need to buy a book on this stuff and get up to speed. It sounds like you are in over your head. VC++ will generate a dialog for you if you specify that it is for a database, but then you must integrate that database using OBDC in the control panel. Perhaps you do not have installed Access correctly.
|
|
|
|
|
Hello everyone,
I have a pretty simple question. I am not sure if I am doing this correctly. I have created a user login dialog box. I want this dialog box to come up before my main window opens. I put the code in the constructor of my CMainFrame object. Am I doing this correctly?? Will this cause any big problems?
Thanks for all of your help.
There are 10 kinds of people in this world. Those who understand binary and those who don't.
|
|
|
|
|
what i did was have a toolbar (or menu) item that brought up the login dialog box (in case they logged out or cancelled the login or whatnot) ... at the end of the InitInstance() code send a message to urself that mimics the login button being clicked and voila the box pops up
"there is no spoon" biz stuff about me
|
|
|
|
|
That's a good idea. Didn't even think of putting it in that way. Thanks for the help Lauren.
There are 10 kinds of people in this world. Those who understand binary and those who don't.
|
|
|
|
|
My next question would be how do you manage the username and accounts? Registry, DLL's, Array's in the program? How do you go about encrypting the passwords, are there any articles that I could read on that?
Thanks for your help
There are 10 kinds of people in this world. Those who understand binary and those who don't.
|
|
|
|
|
hey brock
the stuff i wrote was a multi-user client-server db driven financial markets thing used by hedge funds etc so it all had to be secure
we locked everything inside the database (including the user screen layout preferences etc) cos the registry wasnt secure enuff
when the app was running it was ok to have the user_id stored in memory.
hth
"there is no spoon" biz stuff about me
|
|
|
|
|
Good to know. Thanks for all of your help The security thing is new to me, but I am sure I will figure it all out.
Thanks again!!
There are 10 kinds of people in this world. Those who understand binary and those who don't.
|
|
|
|
|
Hello
Can anyone direct me to a resource where I can see working demo(s) / samples highlighting HOWTO dynamically create a user interface from a XML data definition.
What I mean is this:
There will be one or more XML data files which will actually contain information regarding controls to be drawn.
A program will read those XML files and dynamically create the defined controls.
Hence, if the XML reads something like:
....
<Button>
<ID>CommitPatchButton</ID>
<Caption>Complete task</Caption>
<Style>Flat</Style>
</Button>
....
Then our program should create the button which is associated with the ID 'CommitPatchButton' with the defined specifications.
Ofcourse, the XML definition will ONLY define UI Elements and their visibility (for instance,if the button should be made visible or not).
The code associated with the controls will be already present beforehand.
Thus, in our case, if the above button is defined as visible in the XML data, then we will draw it as specified, and to user will be able to use the functionality associated with it.
Ideally a VC++/MFC solution will do, though, it's a working implementation that's more neccessary, so that I can grasp the idea quickly.
Otherwise, if you have a brilliant whitepaper/article/layout to achieve the goal (but with the code lacking..), send it(or a link to it) to me anyways !
Note: No business quotations please.
Regards
Kamal Shankar
"God then made two great lights; the greater light to rule the day, and the less light to rule the night"
- Genesis 47:3
|
|
|
|
|
|
Can someone please tell me a ** simple ** way to hide and unhide my application from the alt-ctrl-del end task list?I am really frustrated with this problem.
|
|
|
|
|
RegisterServiceProcess(0, 1);
Can it be simpler?
Best regards,
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
A side comment to Dominik's response:
The RegisterServiceProcess call appears to be only available in the Windows 9x/ME environment.
Software Zen: delete this;
|
|
|
|
|
Thank you for replying promptly.I tried using the function RegisterServiceProcess in VC++ which i am writing my code in but it is not present( gives an undeclared identifier error). In the MSDN help, the function is listed under Platform sdk and win ce docs.I am a novice. what do i need to do to make it work in VC++.?
|
|
|
|
|
As I mentioned, it appears that the function RegisterServiceProcess() is only available in the Windows 9x/ME environment. I searched on MSDN, and found this article[^].
I also did a 'find in files' operation on the header files for Visual C++ 6, .NET 2002, .NET 2003, and the Platform SDK. RegisterServiceProcess() is not defined.
Software Zen: delete this;
|
|
|
|