File Handle

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

File Handle

Ingo Blank
Hi,

I'm implementing an interface to a stream library written in C.
This lib relies on the CRTLib <file descriptor> as returned by
open or dup.

Is it by any chance possible to obtain this "C"ish fd from a Win32 HANDLE
(CreateFile) ?

If this is the case, the matter is pretty simple by subclassing class File.
Otherwise I have to implement the whole stream protocol.

TIA

Ingo


Reply | Threaded
Open this post in threaded view
|

Re: File Handle

Ingo Blank
While thinking a little longer about this, I believe that's not possible,
because the <file descriptor> is nothing else than a pointer to a CRT
specific C struct.
Since this struct is simply not there when calling the low level CreateFile,
my question becomes obsolete. Right ?

Have a nice 1st of May
Ingo


"Ingo Blank" <[hidden email]> schrieb im Newsbeitrag
news:3aee7d53$0$9334$[hidden email]...

> Hi,
>
> I'm implementing an interface to a stream library written in C.
> This lib relies on the CRTLib <file descriptor> as returned by
> open or dup.
>
> Is it by any chance possible to obtain this "C"ish fd from a Win32 HANDLE
> (CreateFile) ?
>
> If this is the case, the matter is pretty simple by subclassing class
File.
> Otherwise I have to implement the whole stream protocol.
>
> TIA
>
> Ingo
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: File Handle

Christopher J. Demers
In reply to this post by Ingo Blank
Ingo Blank <[hidden email]> wrote in message
news:3aee7d53$0$9334$[hidden email]...
> Hi,
>
> I'm implementing an interface to a stream library written in C.
> This lib relies on the CRTLib <file descriptor> as returned by
> open or dup.
>
> Is it by any chance possible to obtain this "C"ish fd from a Win32 HANDLE
> (CreateFile) ?
>

This is a little outside of the area I normal work in Dolphin, but I wonder
if these methods might be of use  (you may have already seen these, but I
thought it was worth mentioning):

in the CRTLibrary class

connectDescriptor: fdInteger toWinStdHandle: stdHandleInteger mode:
modeString
"Private - Connect the CRT FILE with the descriptor/index, fdInteger, to the
standard Win32 OS file
 handle identified by the constant, stdHandleInteger. Answer the handle of
the CRT file stream.
 This is necessary to correctly associate CRT stdin/stdout streams with the
correct OS file handles after
 allocating a console in a GUI app. See MSDN article Q105305."

or

_open_osfhandle: osfhandle flags: flags

or

_dup: anInteger
 "Duplicate a file handle
  int_dup( int handle );"


Reply | Threaded
Open this post in threaded view
|

Re: File Handle

Ingo Blank
Chris,

> This is a little outside of the area I normal work in Dolphin, but I
wonder
> if these methods might be of use  (you may have already seen these, but I
>
> _open_osfhandle: osfhandle flags: flags
>


thank you for pointing me there. This one does what I need.

The rest is now very easy.

MyFileSubclass >> open:mode:

open: path mode: fMode
|cHandle flags|
super open: path mode: fMode.
flags := fMode = #read ifTrue:[0] ifFalse:[2].
cHandle := CRTLibrary default _open_ofshandle: self handle flags: flags.
myFileHandle := MyStreamLibrary default open: cHandle mode: fMode.
^self

Thanks again
Ingo