Page 1 of 1

How do I execute Win32 functions?

Posted: Wed Jul 26, 2023 9:51 pm
by rex
How do I execute Win32 functions?
For instance, in APL+Win I can execute the Windows GetTempPath function to query the user's temp directory with:
⎕WCALL 'GetTempPath' 128 (128⍴⎕TCNUL)  
 32 C:\Users\rex\AppData\Local\Temp\
How does one do this in Dyalog?

(I am a very experienced APL programmer, but new to Dyalog.)

Re: How do I execute Win32 functions?

Posted: Thu Jul 27, 2023 3:20 pm
by JoHo
Hi Rex,
this would be ⎕NA, for Name Association
There is a QuadNA.dws with examples in the namespace Windows.
Greetings,
JoHo

Re: How do I execute Win32 functions?

Posted: Thu Jul 27, 2023 3:31 pm
by rex
Thanks a lot -- that will get me started.

Re: How do I execute Win32 functions?

Posted: Thu Jul 27, 2023 3:41 pm
by JoHo
copied from the ⎕NA docu, "more examples":

Code: Select all

      ⎕←GetTempDir''
C:\Users\Alpha\AppData\Local\Temp\

      ⎕VR'GetTempDir'
     ∇ {temp}←GetTempDir dummy;get;size
[1]    'get'⎕NA'U4 kernel32|GetTempPath*   U4 >0T' ⍝ 
[2]    (size temp)←get 128 128
     ∇


Re: How do I execute Win32 functions?

Posted: Fri Jul 28, 2023 3:53 am
by petermsiegel
Of course, for this specific example, there's

Code: Select all

   739⌶0   ⍝ Return temporary dir name on this o/s
/tmp
and there's ⎕SH (or ⎕CMD, the Windows-style name) to execute relatively arbitrary host O/S commands.

Re: How do I execute Win32 functions?

Posted: Fri Jul 28, 2023 2:06 pm
by PGilbert
If you don't mind using .Net here is what I am using:

To start a Win32 function:

Code: Select all

⎕USING∪←⊂',System.dll'
sink←System.Diagnostics.Process.Start(⊂'notepad.exe')
sink←System.Diagnostics.Process.Start(⊂'calc.exe')
sink←System.Diagnostics.Process.Start(⊂'C:\Program Files (x86)\Dyalog')
To get the TempPath:

Code: Select all

⎕USING∪←⊂',mscorlib.dll'
System.IO.Path.GetTempFileName

Re: How do I execute Win32 functions?

Posted: Sat Jul 29, 2023 10:07 pm
by rex
Ha ha -- the usual APL situation:
many possible solutions, quite different from each other.
Thank you, everyone.