Win32 API Struct

Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2005
Posts: 4
Reputation: PatrikK is an unknown quantity at this point 
Solved Threads: 0
PatrikK PatrikK is offline Offline
Newbie Poster

Win32 API Struct

 
0
  #1
May 27th, 2005
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:
  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:

  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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Win32 API Struct

 
0
  #2
May 27th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 4
Reputation: PatrikK is an unknown quantity at this point 
Solved Threads: 0
PatrikK PatrikK is offline Offline
Newbie Poster

Re: Win32 API Struct

 
0
  #3
May 27th, 2005
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..
  1. $value=$Block->{User}->{Address};
  2. or with tie:
  3. $value=$Block{User}->{Address};
next i tried this:
  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..
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 4
Reputation: PatrikK is an unknown quantity at this point 
Solved Threads: 0
PatrikK PatrikK is offline Offline
Newbie Poster

Re: Win32 API Struct

 
0
  #4
May 27th, 2005
and this is what a dump shows :
  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 ...
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Win32 API Struct

 
0
  #5
May 27th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 4
Reputation: PatrikK is an unknown quantity at this point 
Solved Threads: 0
PatrikK PatrikK is offline Offline
Newbie Poster

Re: Win32 API Struct

 
0
  #6
May 29th, 2005
Hi again,

Ok ill keep trying on this one .. if i find a solution i will post it here
thanks for trying though
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 4016 | Replies: 5
Thread Tools Search this Thread



Tag cloud for Perl
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC