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.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to