API Calls for Squeak 1.3
Alejandro F. Reimondo
alereimondo at sugarweb.com
Tue Jan 20 14:17:56 UTC 1998
>Why not change the code to:
>KernelDLL class methodsFor: 'opening' stamp: 'afr 1/14/98 21:52'!
>getCurrent
> "Private - get (open) an instance of the receiver."
>
> ^self fromInteger: self new getHandle.
>Remember, getCurrent should answer something which becomes current. >The setting of current is handled up in the hierarchy. Now, getCurrent also
> sets the current.
Yes!, ok you are right; thanks.
>We've got things compiled and running. When evaluating the getVersion
>example it prints 16r4 (good!) but when I evaluate the WinExec 'calc.exe'
>the Windows Calculator comes up and then Squeak crashes in Win32Alloc
>(vMemIsReservedPage...Query) etc. After testing 3 or more examples leading
>to the same result we stopped.
I've noticed some problems:
1.- Structures MUST be defined in external (fixed) memory :-(
2.- API must be changed to acept them.
3.- SeldDefinedStructure for StartUpInfo was wrong.
The right code for API call is:
---Cut here--------------------------------------
!KernelDLL methodsFor: 'api calls'!
createProcess: imageName
commandLine: commandLine
processSecurity: processSecurity
threadSecurity: threadSecurity
inheritHandles: aBoolean
createFlags: createFlags
environment: environmentString
currentDir: directoryString
startInfo: startupInfo
processInfo: processInfo
<api: CreateProcessA struct struct struct struct boolean ulong struct struct ulong ulong boolean >
^self invalidArgument!
---Cut here and fileItIn-----------------------
The right code for the DoIt chunk is.....
---Cut here--------------------------------------
| startupInfo processInfo aPathName |
ExternalHandle startUp.
"Here we define needed structures..."
Dynalink32
registerType: 'STARTUPINFO'
as: #(
(cb ulong)
(reserved ulong)
(desktop ulong)
(title ulong)
(x ulong)
(y ulong)
(xSize ulong)
(ySize ulong)
(xCountChars ulong)
(yCountChars ulong)
(fillAttribute ulong)
(flags ulong)
(showWindow ushort)
(cbReserved2 ushort)
(lpReserved2 ulong)
(hStdInput ulong)
(hStdOutput ulong)
(hStdError ulong)
);
registerType: 'PROCESSINFORMATION'
as: #(
(hProcess ulong)
(hThread ulong)
(dwProcessId dword)
(dwThreadId dword)
);
yourself.
"Now, we can fill the structures and call the API"
aPathName := 'calc.exe'.
startupInfo := Dynalink32 externalStructureNamed: 'STARTUPINFO'.
startupInfo cb: startupInfo sizeInBytes; showWindow: 1.
processInfo := Dynalink32 externalStructureNamed: 'PROCESSINFORMATION'.
( KernelDLL current
createProcess: nil commandLine: aPathName asParameter
processSecurity: nil threadSecurity: nil
inheritHandles: false createFlags: 0
environment: nil currentDir: nil
startInfo: startupInfo asParameter
processInfo: processInfo asParameter )
ifFalse: [ ^self osError ].
startupInfo release.
processInfo release.
---Cut here and DoIt-------------------------------
Bye.
Ale.
More information about the Squeak-dev
mailing list
|