943,929 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 4549
  • Perl RSS
May 27th, 2005
0

Win32 API Struct

Expand Post »
Hi ,

I have been trying to use the win32::APItruct 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)
  1. Win32::API::Struct->typedef('MDS_Forwarding', qw(
  2. char Address[257];
  3. char Host[64];
  4. char SendAs[128];
  5. char Port[8];
  6. )) or die "Typedef error $!\n";
  7.  
  8. Win32::API::Struct->typedef('MDS_Block', qw(
  9. MDS_Forwarding User;
  10. char Name[64];
  11. )) or die "Typedef error $!\n";

if i define a MDS_Block struct like this:

Perl Syntax (Toggle Plain Text)
  1. 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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
PatrikK is offline Offline
4 posts
since May 2005
May 27th, 2005
0

Re: Win32 API Struct

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
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
May 27th, 2005
0

Re: Win32 API Struct

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..
Perl Syntax (Toggle Plain Text)
  1. $value=$Block->{User}->{Address};
  2. or with tie:
  3. $value=$Block{User}->{Address};
next i tried this:
Perl Syntax (Toggle Plain Text)
  1. 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..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
PatrikK is offline Offline
4 posts
since May 2005
May 27th, 2005
0

Re: Win32 API Struct

and this is what a dump shows :
Perl Syntax (Toggle Plain Text)
  1. $VAR1 = 'User';
  2. $VAR2 = bless( {
  3. 'typedef' => [
  4. [
  5. 'Address',
  6. 'c*257',
  7. 'char'
  8. ],
  9. [
  10. 'Host',
  11. 'c*64',
  12. 'char'
  13. ],
  14. [
  15. 'SendAs',
  16. 'c*128',
  17. 'char'
  18. ],
  19. [
  20. 'Port',
  21. 'c*8',
  22. 'char'
  23. ]
  24. ],
  25. '__typedef__' => 'MDS_Forwarding'
  26. }, 'Win32::API::Struct' );
  27. $VAR3 = 'Name';
  28. $VAR4 = undef;
Last edited by PatrikK; May 27th, 2005 at 5:36 pm. Reason: use code tags ...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
PatrikK is offline Offline
4 posts
since May 2005
May 27th, 2005
0

Re: Win32 API Struct

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.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
May 29th, 2005
0

Re: Win32 API Struct

Hi again,

Ok ill keep trying on this one .. if i find a solution i will post it here
thanks for trying though
Reputation Points: 10
Solved Threads: 0
Newbie Poster
PatrikK is offline Offline
4 posts
since May 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: Guestbook help. Post in two different spots.
Next Thread in Perl Forum Timeline: Posting Large amounts of text from Guestbook





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC