Re: NativeCall and pointers question

2022-11-30 Thread ToddAndMargo via perl6-users

On 11/30/22 12:53, ToddAndMargo via perl6-users wrote:

Let me ask this question a little simpler:



To answer my own questions, which I figured out
the hard way.


1) how to I tell NativeCall I only want the
C pointer back, not what it points to?


By declaring it as a pointer and creating it with
".new".   No ".new", and you get back garbage.

sub GetWTSEnumerateSession(
   #`{
   C++
   BOOL WTSEnumerateSessionsA(
 [in]  HANDLE hServer,
 [in]  DWORD  Reserved,
 [in]  DWORD  Version,
 [out] PWTS_SESSION_INFOA *ppSessionInfo,
 [out] DWORD  *pCount
   );
   Returns zero if this function fails.
   }
   DWORD $hServer,   # [in]  HANDLE
   DWORD $Reserved,  # [in] always 0
   DWORD $Version,   # [in] always 1
   Pointer $ppSessionInf is rw,  # [out] <---
   DWORD $pCount is rw   # [out] DWORD
   )
   is native("Wtsapi32.dll")
   is symbol("WTSEnumerateSessionsA")
   returns DWORD  # If the function fails, the return value is zero.
   { * };


   my $ppSessionInfo = NativeCall::Types::Pointer.new();





2) how do I tell NativeCall I am sending it
a C pointer?


Declare it a Pointer, same as above.  See

   my $ppSessionInfo

Do not forget the .new.  There are no
error warnings if you forget.  The resulting
garbage yo get back will drive you nuts,
especially when the next API call that
reuses that point will cause your program to
exit with not explanation.



Yours in confusion (but not this, finally),
-T

--
~~~
Serious error.
All shortcuts have disappeared.
Screen. Mind. Both are blank.
~~~


When to use .new?

2022-11-30 Thread ToddAndMargo via perl6-users

Hi All,

Why can I get away with

   my Str $x = "";

But I have to use .new here (an other places too)

   my $ppSession = NativeCall::Types::Pointer.new();


Is there some rule I can follow that let me know
when I have to use .new and when I do not?
(I am getting tired of figuring it out the
hard way.)

Many thanks,
-T



Re: [sf-perl] The SF Perl Raku Study Group (postponed)

2022-11-30 Thread deloreanx via perl6-users
Sounds good to me.


Sent from Yahoo Mail for iPhone


On Monday, November 28, 2022, 9:30 PM, Joseph Brenner  wrote:

On the next few Sundays, I've got some schedule conflicts, so I've got
to skip holding the Raku Study Group when we usually would on December
4th.

Instead the next meeting will be on December 18th, and after that
we'll most likely do one on New Years Day itself, January 1st, 2023.
___
SanFrancisco-pm mailing list
sanfrancisco...@pm.org
https://mail.pm.org/mailman/listinfo/sanfrancisco-pm





Re: NativeCall and pointers question

2022-11-30 Thread ToddAndMargo via perl6-users

Let me ask this question a little simpler:

1) how to I tell NativeCall I only want the
C pointer back, not what it points to?

2) how do I tell NativeCall I am sending it
a C pointer?

Many thanks,
-T



NativeCall and pointers question

2022-11-30 Thread ToddAndMargo via perl6-users

Hi All,

In the following:

use NativeCall;
constant BYTE := uint8;
constant LPDWORD  := uint64;# long pointer to a DWORD
constant LPSTR= CArray[BYTE];   # long pointer to a string
constant DWORD:= uint32;
constant HANDLE   = Pointer[void];

sub WTSOpenServerA(
  #`{

https://learn.microsoft.com/en-us/windows/win32/api/wtsapi32/nf-wtsapi32-wtsopenservera?redirectedfrom=MSDN
  C++
  HANDLE WTSOpenServerA(
  [in] LPSTR pServerName
  );
   }

   LPSTR $pServerName
   )

   is native("Wtsapi32.dll")
   is symbol("WTSOpenServerA")
   returns DWORD
   { * };


NativeCall is resolving the pointers automatically
for me.  It is taking $pServerName, which is a
Long Pointer to String (LPSTR) and creating the
pointer for me.  This is appreciated.

It also returns and resolves the value of “HANDLE”
which is a C Pointer DWORD..

Question 1:  how do I tell NativeCall I actually
want the C Pointer of HANDLE  back and not what
it resolves to?

Question 2: how do I give NativeCall a pointer
value and tell Native call I do not want it
resolved into another pointer?

Many thanks,
-T