Hi ,

I have been trying to use the win32::API:Struct 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 ..


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:

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

12 Years
Discussion Span
Last Post by PatrikK

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..:)

or with tie:

next i tried this:

foreach my $K (keys($Block{User})) {print "\n$K";}

but no luck...
if you have any more tips im all ears :)


and this is what a dump shows :

$VAR1 = 'User';
$VAR2 = bless( {
                 'typedef' => [
                 '__typedef__' => 'MDS_Forwarding'
               }, 'Win32::API::Struct' );
$VAR3 = 'Name';
$VAR4 = undef;

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.


Hi again,

Ok ill keep trying on this one .. if i find a solution i will post it here
thanks for trying though :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.