Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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

by tye (Sage)
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        

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1034858]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2018-06-22 10:26 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (124 votes). Check out past polls.