Click here to Skip to main content
16,004,977 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Copying structs into a BYTE array Pin
Wheatbread23-Apr-04 11:21
Wheatbread23-Apr-04 11:21 
GeneralRe: Copying structs into a BYTE array Pin
Gary R. Wheeler23-Apr-04 11:35
Gary R. Wheeler23-Apr-04 11:35 
GeneralRe: Copying structs into a BYTE array Pin
Wheatbread23-Apr-04 11:47
Wheatbread23-Apr-04 11:47 
GeneralRe: Copying structs into a BYTE array Pin
Rick York23-Apr-04 11:57
mveRick York23-Apr-04 11:57 
GeneralRe: Copying structs into a BYTE array Pin
Tim Smith23-Apr-04 16:04
Tim Smith23-Apr-04 16:04 
GeneralRe: Copying structs into a BYTE array Pin
Rick York23-Apr-04 20:52
mveRick York23-Apr-04 20:52 
GeneralRe: Copying structs into a BYTE array Pin
Tim Smith24-Apr-04 4:05
Tim Smith24-Apr-04 4:05 
GeneralRe: Copying structs into a BYTE array Pin
Paul Ranson24-Apr-04 4:37
Paul Ranson24-Apr-04 4:37 
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()
{
    // prepare a UserInfo
    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
GeneralRe: Copying structs into a BYTE array Pin
Wheatbread25-Apr-04 5:55
Wheatbread25-Apr-04 5:55 
GeneralPlease help!!! Dialogs problem Pin
Anton P. Ivanov23-Apr-04 9:55
Anton P. Ivanov23-Apr-04 9:55 
GeneralRe: Please help!!! Dialogs problem Pin
Jeff Bogan23-Apr-04 10:38
Jeff Bogan23-Apr-04 10:38 
GeneralCreating a user login Pin
BrockVnm23-Apr-04 9:41
BrockVnm23-Apr-04 9:41 
GeneralRe: Creating a user login Pin
l a u r e n23-Apr-04 11:20
l a u r e n23-Apr-04 11:20 
GeneralRe: Creating a user login Pin
BrockVnm23-Apr-04 11:39
BrockVnm23-Apr-04 11:39 
GeneralRe: Creating a user login Pin
BrockVnm26-Apr-04 5:54
BrockVnm26-Apr-04 5:54 
GeneralRe: Creating a user login Pin
l a u r e n26-Apr-04 8:57
l a u r e n26-Apr-04 8:57 
GeneralRe: Creating a user login Pin
BrockVnm26-Apr-04 9:01
BrockVnm26-Apr-04 9:01 
GeneralHelp on dynamically creating UI elements based on XML data required Pin
Kamal Shankar23-Apr-04 9:14
Kamal Shankar23-Apr-04 9:14 
GeneralRe: Help on dynamically creating UI elements based on XML data required Pin
l a u r e n23-Apr-04 11:20
l a u r e n23-Apr-04 11:20 
GeneralHiding application from the ALT CTLR DEL list Pin
Arnav23-Apr-04 9:01
Arnav23-Apr-04 9:01 
GeneralRe: Hiding application from the ALT CTLR DEL list Pin
Dominik Reichl23-Apr-04 10:11
Dominik Reichl23-Apr-04 10:11 
GeneralRe: Hiding application from the ALT CTLR DEL list Pin
Gary R. Wheeler23-Apr-04 11:16
Gary R. Wheeler23-Apr-04 11:16 
GeneralRegisterServiceProcess not working in VC++ Pin
Arnav24-Apr-04 8:47
Arnav24-Apr-04 8:47 
GeneralRe: RegisterServiceProcess not working in VC++ Pin
Gary R. Wheeler27-Apr-04 14:31
Gary R. Wheeler27-Apr-04 14:31 
GeneralMultiple threads and ADO Pin
nanukos23-Apr-04 8:22
nanukos23-Apr-04 8:22 

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.