kernel32.dll OpenFile

J.madray

New Member
Hi.
I'm trying to open a file using a kernel32.dll method.
I need to open many files using associated application (Word, excel, acrobat reader, outlook, outlook express...)

I'm trying with method "OpenFile" but I always get an error message :

'C' Call Stack has been compromised after calling _OpenFile@4 in kernel32.dll (6069)

I'm not sure about the arguments I used and the type I gave them.

PROCEDURE OpenFile EXTERNAL "kernel32.dll" :
DEFINE OUTPUT PARAMETER FileHandle AS CHARACTER.
DEFINE INPUT PARAMETER DesiredAccess AS CHARACTER.
DEFINE INPUT PARAMETER ObjectAttributes AS CHARACTER.
DEFINE OUTPUT PARAMETER IoStatusBlock AS CHARACTER.
DEFINE INPUT PARAMETER ShareAccess AS CHARACTER.
DEFINE INPUT PARAMETER OpenOptions AS CHARACTER.
END PROCEDURE.

Help..
thx.
 
The error is caused because the definition you have for OpenFile is incorrect. FileOpen has three input parameters (Filename, Pointer to a file information buffer and an int flag of action attributes).

Perhaps OpenFile isn't what you are after. What are you trying to achieve? It sounds like you may want to execute the associated application for a given file, in which case you should be looking at the ShellExecuteEx procedure. If you need to wait for the application to close before resuming you code you will also need to look at WaitForSingleObject.

Hope this is enough to get you started.
 
Hi.

I'm using the procedure

ShellExecuteA
(0,"Open",f-file:SCREEN-VALUE IN FRAME {&FRAME-NAME},"","",1,OUTPUT iError).

But this procedure doesn't run as I want.
It s opening Word, excel and other files type, but not ".err" files associated with "Ultraedit".
 
Sounds like you are most of the way there.

I'd Check the ".err" file type and ensure a application is setup for the "open" action. you could try and remove the err extension type and re-add if you are still not getting the right result.
 
I have found an other solution wich works.

DEFINE VARIABLE v-file AS COM-HANDLE NO-UNDO.

CREATE "shell.Application" v-file CONNECT NO-ERROR.
IF NOT VALID-HANDLE(v-file)
THEN CREATE "shell.Application" v-file.

v-file:OPEN(f-file:SCREEN-VALUE IN FRAME {&FRAME-NAME}).

RELEASE OBJECT v-file NO-ERROR.

RETURN.
 
".txt" files are associated with "ultraedit.exe"

with "ShellExecute" the ".txt" files are openned with "Write.exe".
with "Shell.application" the ".txt" files are openned with "ultraedit.exe".

cya.
 
Back
Top