develooper Front page | perl.perl6.users | Postings from November 2022

Re: NativeCall pointer question?

Thread Previous | Thread Next
From:
ToddAndMargo via perl6-users
Date:
November 25, 2022 04:23
Subject:
Re: NativeCall pointer question?
Message ID:
91b70b3b-60c1-d9b3-d51d-07586794f78b@zoho.com
>> On Sun, Nov 20, 2022 at 3:48 AM ToddAndMargo via perl6-users 
>> <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
>> 
>>     Hi All,
>> 
>>     In one of my native call, I get returned a
>>     pointer to a DWORD (uint32).
>> 
>>     How do I turn that into the actual value
>>     in the DWORD?
>> 
>>     Many thanks,
>>     -T

On 11/20/22 16:00, Clifton Wood wrote:
> @ToddAndMargo,
> 
> Two ways:
> 
>   - Use "my CArray[uint32] $p", use $p as your parameter, and access the 
> value as "$p[0]"
> 
> or
> 
> - Use "my Pointer[uint32] $p"  and use "$p.deref"
> 
> My personal preference is the former, as it is the best way to access 
> AND set the actual former value. The latter can only deref. To my 
> knowledge, you cannot set the referenced value of a Pointer type. I do 
> reserve the right to be wrong on this, though.


Hi Clifton,

I have a pointer $p (from a Windows API call)
that points to a spot in memory that is 24
bytes long.

# Where do I tell it I want 24 bytes back?
my $ca = CArray[uint8].new( 0xFF ** 24 )
$ca = $p.deref;

Internal error: unhandled target type


Yours in confusion,
-T


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About