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

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]
[Corion]: marto: How's things? I hope the kids are fine and you too!
[Corion]: Oh yay. I wonder why a very simple change in a program doesn't elicit a diff, and now I see that my diff program seems to have a bug ;)
[1nickt]: marto thanks for asking, so far so good. A pretty modern stack and decent procedures, although rather too much home-built stuff (e.g. a logging role that should tries to duplicate Log::Any).
[Corion]: No. It's just that I'm comparing the same output file twice, instead of comparing the output files of the two runs %-)
[Corion]: Lo and behold, running a program with the correct input files yields the correct (and expected) output. Yay me.
[1nickt]: Got a MacBook and am expected to develop directly on it, ironic given the recent thread about that.
[marto]: Corion, some not too serious issues with the kids, hopefully, other than that just dealing with commuting by car again in the winter, not much fun so far, and there's no real 'bad' weather yet :)
[marto]: 1nickt, glad to hear it, I'm sure you'll bring improvements to their stack in due course ;)

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2017-12-11 11:41 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (289 votes). Check out past polls.