Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Win32::API pointers / NULL (N not P)

by tye (Cardinal)
on May 23, 2013 at 04:41 UTC ( #1034858=note: print w/ replies, xml ) Need Help??


in reply to Win32::API pointers / NULL

"P" doesn't support NULL (last time I messed with this which was a long time ago). It isn't much of a "pointer" type, it is more of a "string" type. But NULL is just a 0 so change the "P" to "N" and pass a 0 in.

Note that this means you'll need separate Win32::API objects for passing a NULL vs. passing a non-NULL pointer. Or you can just construct the number that represents the desired pointer value:

my $ptr = unpack "N", pack "P", $struct;

But getting that exactly right might be harder than that example, especially if you have 64-bit parts of your Perl build. So you might be better off with multiple Win32::API objects if you have both NULL and non-NULL values to deal with for the same argument.

[Update: This is why I came up with a "not at all like a string" argument value that always means "I want a NULL pointer" for users of Win32API:: modules (like Win32API::File, modules that have nothing to do with Win32::API other than, of course, having to deal with Win32 APIs). It might be a nice enhancement to Win32::API to teach it to similarly treat a ref to an empty array being passed in for a "P" argument as a request to pass a NULL pointer to the underlying API. Then you could just pass in [] instead of a packed 'struct' when you want a NULL. ]

- tye        


Comment on Re: Win32::API pointers / NULL (N not P)
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1034858]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2014-11-21 03:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (104 votes), past polls