| | |
Win32 API Struct
Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2005
Posts: 4
Reputation:
Solved Threads: 0
Hi ,
I have been trying to use the win32::API
truct for a while and mostly it works fine 
However i have ran into trouble with using structs within structs ... I dont know how to retrieve values from the nested struct ..
example:
if i define a MDS_Block struct like this:
How do i retrieve the nested Address value for the $Block struct??
Thanks in advance!
Patrik K
I have been trying to use the win32::API
truct for a while and mostly it works fine 
However i have ran into trouble with using structs within structs ... I dont know how to retrieve values from the nested struct ..
example:
Perl Syntax (Toggle Plain Text)
Win32::API::Struct->typedef('MDS_Forwarding', qw( char Address[257]; char Host[64]; char SendAs[128]; char Port[8]; )) or die "Typedef error $!\n"; Win32::API::Struct->typedef('MDS_Block', qw( MDS_Forwarding User; char Name[64]; )) or die "Typedef error $!\n";
if i define a MDS_Block struct like this:
Perl Syntax (Toggle Plain Text)
my $Block = Win32::API::Struct->new( 'MDS_Block' );
How do i retrieve the nested Address value for the $Block struct??
Thanks in advance!
Patrik K
I'm pretty sure that if you tie the first struct, you can reference it as a hash, and then it will be like having a hash of structs. I could be wrong, but have you looked at:
http://search.cpan.org/~acalpini/Win...0.41/Struct.pm
Read the section near the bottom that discusses using tied structs, and hopefully that will help. Let me know how it turns out
http://search.cpan.org/~acalpini/Win...0.41/Struct.pm
Read the section near the bottom that discusses using tied structs, and hopefully that will help. Let me know how it turns out
•
•
Join Date: May 2005
Posts: 4
Reputation:
Solved Threads: 0
Hi Comatose and thanks for answering! 
im not really sure what you mean, what im trying to do is the following:
the structs are defined in API documentation for an application i want to control by perl. A pointer to this struct is sent in an api call and the application fills the struct with data. I then want to read and/or change the data in the struct as applicable , then another dll call submits the edited struct to the application.
If I understood you correctly you suggested to tie the first (the one that is nested inside the second) but I never instance the first struct .. it is only defined so that the struct i want to use for the dll call can be properly defined.
I mistakenly thought something like this would work to access it..
next i tried this:
but no luck...
if you have any more tips im all ears
/P

im not really sure what you mean, what im trying to do is the following:
the structs are defined in API documentation for an application i want to control by perl. A pointer to this struct is sent in an api call and the application fills the struct with data. I then want to read and/or change the data in the struct as applicable , then another dll call submits the edited struct to the application.
If I understood you correctly you suggested to tie the first (the one that is nested inside the second) but I never instance the first struct .. it is only defined so that the struct i want to use for the dll call can be properly defined.
I mistakenly thought something like this would work to access it..

Perl Syntax (Toggle Plain Text)
$value=$Block->{User}->{Address}; or with tie: $value=$Block{User}->{Address};
Perl Syntax (Toggle Plain Text)
foreach my $K (keys($Block{User})) {print "\n$K";}
but no luck...
if you have any more tips im all ears

/P
Last edited by PatrikK; May 27th, 2005 at 4:37 pm. Reason: spelling..
•
•
Join Date: May 2005
Posts: 4
Reputation:
Solved Threads: 0
and this is what a dump shows :
Perl Syntax (Toggle Plain Text)
$VAR1 = 'User'; $VAR2 = bless( { 'typedef' => [ [ 'Address', 'c*257', 'char' ], [ 'Host', 'c*64', 'char' ], [ 'SendAs', 'c*128', 'char' ], [ 'Port', 'c*8', 'char' ] ], '__typedef__' => 'MDS_Forwarding' }, 'Win32::API::Struct' ); $VAR3 = 'Name'; $VAR4 = undef;
Last edited by PatrikK; May 27th, 2005 at 5:36 pm. Reason: use code tags ...
I'm out of ideas on this one. I know that I was hoping that using tie would would allow you to access the elements of the child struct by using the parent struct as a hash-like system. I'm sorry, but I don't know how to do what you want. If you figure out a solution, please post so that I, and others who are dumbfounded by this, have the solution available. I would normally have suggested the use of a parent hash, with a child struct, but I know that wouldn't work for your project. Please let us know if you find the solution.
![]() |
Similar Threads
- Creating A Table With Win32 Api (C++)
- anyone understand win32 api? (C)
- Win32 Perl - CreateProcess (Perl)
- How to Install Perl Mod Win32-API (Perl)
Other Threads in the Perl Forum
- Previous Thread: Guestbook help. Post in two different spots.
- Next Thread: Posting Large amounts of text from Guestbook
Views: 4016 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for Perl






