HELP WANTED!

new topic     » topic index » view thread      » older message » newer message

This is a multi-part message in MIME format.

------=_NextPart_000_0009_01C30D99.5528CB00
	charset="iso-8859-1"

Hello all,

I have been waiting to implement Cab file wrappers (Cabinet.dll)
I thought once Robert C. had made cdecl available to us
that I could whip-up a working set but, I am totally confused about
this very mysterious .dll

Here is code I have tried (below), I have also tried fptr.e by Matt =
Lewis
and code published by mic and none have worked. Perhaps this should
work before Robert C. post 2.4 final?

I hope someone will guide me in the correct direction if it's even =
possible.
    =20
          *look for -- MACHINE LEVEL CRASH HERE!*

<code by Euman 2003>

with trace

include dll.e
include misc.e

integer xHeapCreate, xHeapDestroy, xHeapAlloc, xHeapFree,=20
        xCreateFile, xReadFile, xWriteFile, xSetFilePointer, =
xCloseHandle,
        xFDICreate, xFDIIsCabinet, xFDICopy, xFDIDestroy
       =20
procedure not_found(sequence name)
    puts(1, "Couldn't find " & name & '\n')
    abort(1)
end procedure

function link_c_func(atom dll, sequence name, sequence args, atom =
result)
 integer handle

   handle =3D define_c_func(dll, name, args, result)
   if handle =3D -1 then
      not_found(name)
   else
      return handle
   end if
end function

function link_c_proc(atom dll, sequence name, sequence args)
 integer handle
   handle =3D define_c_proc(dll, name, args)
   if handle =3D -1 then
      not_found(name)
   else
      return handle
   end if
end function

procedure link_dll_routines()
  atom kernel32, cabinet
   =20
    kernel32 =3D open_dll("kernel32.dll")
    if kernel32 =3D NULL then
 not_found("kernel32.dll")
    end if   =20
    cabinet =3D open_dll("cabinet.dll")
    if cabinet =3D NULL then
 not_found("cabinet.dll")
    end if   =20

    xHeapCreate =3D =
link_c_func(kernel32,"HeapCreate",{C_LONG,C_LONG,C_LONG},C_LONG)
    xHeapDestroy =3D link_c_func(kernel32,"HeapDestroy",{C_LONG},C_LONG)
    xHeapAlloc =3D =
link_c_func(kernel32,"HeapAlloc",{C_LONG,C_LONG,C_LONG},C_LONG)
    xHeapFree =3D =
link_c_func(kernel32,"HeapFree",{C_LONG,C_LONG,C_LONG},C_LONG)

    xCreateFile =3D =
link_c_func(kernel32,"CreateFileA",{C_POINTER,C_LONG,C_LONG,C_POINTER,C_L=
ONG,C_LONG,C_INT},C_LONG)
    xReadFile =3D =
link_c_func(kernel32,"ReadFile",{C_INT,C_POINTER,C_UINT,C_POINTER,C_POINT=
ER},C_LONG)
    xWriteFile =3D =
link_c_func(kernel32,"WriteFile",{C_INT,C_POINTER,C_LONG,C_POINTER,C_POIN=
TER},C_LONG)
    xSetFilePointer =3D =
link_c_func(kernel32,"SetFilePointer",{C_LONG,C_LONG,C_POINTER,C_LONG},C_=
LONG)
    xCloseHandle =3D link_c_func(kernel32,"CloseHandle",{C_LONG},C_LONG)

    xFDICreate =3D =
link_c_func(cabinet,"FDICreate",{C_POINTER,C_POINTER,C_POINTER,C_POINTER,=
C_POINTER,C_POINTER,C_POINTER,C_INT,C_LONG},C_LONG)
    xFDIIsCabinet =3D =
link_c_func(cabinet,"FDIIsCabinet",{C_LONG,C_INT,C_POINTER},C_LONG)
    xFDICopy =3D =
link_c_func(cabinet,"FDICopy",{C_LONG,C_POINTER,C_POINTER,C_INT,C_POINTER=
,C_POINTER,C_INT},C_LONG)
    xFDIDestroy =3D link_c_proc(cabinet,"FDIDestroy",{C_LONG})

end procedure

link_dll_routines()
trace(1)
integer id
object junk

constant HEAP_ZERO_MEMORY=3D#00000008
 =20
global atom pHeap
pHeap =3D c_func(xHeapCreate,{0,16384,0})


global function myalloc(atom size)
   return c_func(xHeapAlloc,{pHeap,HEAP_ZERO_MEMORY,size})
end function
atom PFNALLOC

id =3D routine_id("myalloc")=20
PFNALLOC =3D call_back(id)

global function myfree(atom pmem)
   return c_func(xHeapFree,{pHeap,0,pmem})
end function
atom PFNFREE

id =3D routine_id("myfree")=20
PFNFREE =3D call_back(id)

global procedure mypoke(atom mem, object s)
   poke(mem, s)
end procedure

global procedure mypoke4(atom mem, object s)
   poke4(mem, s)=20
end procedure

global function mypeek(object si)
   if integer(si) then
      return peek(si)     =20
   else
      return peek({si[1],si[2]})=20
   end if
end function

global function mypeek4s(object si)
   if integer(si) then
      return peek4s(si)=20
   else
      return peek4s({si[1],si[2]})=20
   end if
end function

global function mypeek4u(object si)
   if integer(si) then
      return peek4u(si)=20
   else
      return peek4u({si[1],si[2]})=20
   end if
end function

global function allocate_string2(sequence s)
atom mem
    mem =3D myalloc(length(s)+1)
    mypoke(mem, s)
    return mem
end function

global constant GENERIC_READ  =3D #80000000,
  GENERIC_WRITE =3D #40000000,
  FILE_ATTRIBUTE_NORMAL =3D #80,
  FILE_BEGIN             =3D 0,
  FILE_CURRENT               =3D 1,
  FILE_END                   =3D 2,
  FILE_FLAG_WRITE_THROUGH    =3D #80000000,
  FILE_FLAG_OVERLAPPED       =3D #40000000,
  FILE_FLAG_NO_BUFFERING     =3D #20000000,
  FILE_FLAG_RANDOM_ACCESS    =3D #10000000,
  FILE_FLAG_SEQUENTIAL_SCAN  =3D #8000000,
  FILE_FLAG_DELETE_ON_CLOSE  =3D #4000000,
  FILE_FLAG_BACKUP_SEMANTICS =3D #2000000,
  FILE_FLAG_POSIX_SEMANTICS  =3D #1000000,
  CREATE_NEW        =3D 1,
  CREATE_ALWAYS     =3D 2,
  OPEN_EXISTING     =3D 3,
  OPEN_ALWAYS       =3D 4,
  TRUNCATE_EXISTING =3D 5,
  INVALID_HANDLE_VALUE =3D -1
 =20
 =20
global function CreateFile(sequence fname, sequence accmode)
atom File, FileName=20
  FileName =3D allocate_string2(fname)
  if compare(accmode,"rb")=3D0 then
    File =3D =
c_func(xCreateFile,{FileName,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRI=
BUTE_NORMAL+
                               FILE_FLAG_SEQUENTIAL_SCAN,NULL})
  elsif compare(accmode,"wb")=3D0 then
    File =3D =
c_func(xCreateFile,{FileName,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTR=
IBUTE_NORMAL+
                               FILE_FLAG_SEQUENTIAL_SCAN,NULL})
  end if
  junk =3D myfree(FileName)
  return File
end function
atom PFNOPEN

id =3D routine_id("CreateFile")=20
PFNOPEN =3D call_back(id)

 --WriteFile()
 --hFile (handle) obtained by CreateFile=20
 --must have GENERIC_WRITE access

atom writebytes
writebytes =3D myalloc(4)


function WriteFile(atom hFile, atom lpBuffer, atom =
nNumberOfBytesToWrite)
  return =
c_func(xWriteFile,{hFile,lpBuffer,nNumberOfBytesToWrite,writebytes,0})
end function           =20
atom PFNWRITE

id =3D routine_id("CreateFile")=20
PFNWRITE =3D call_back(id)

 --ReadFile()
 --hFile (handle) obtained by CreateFile=20
 --must have GENERIC_READ access

atom readbytes
readbytes =3D myalloc(4) --lpNumberOfBytesRead=20


function ReadFile(atom hFile, atom lpBuffer, atom nNumberOfBytesToRead)
  return =
c_func(xReadFile,{hFile,lpBuffer,nNumberOfBytesToRead,readbytes,0})
end function
atom PFNREAD

id =3D routine_id("ReadFile")=20
PFNREAD =3D call_back(id)


constant SEEK_SET =3D 0,               --/* seek to an absolute position =
*/
         SEEK_CUR =3D 1,               --/* seek relative to current =
position */
         SEEK_END =3D 2 =20
        =20

function SetFilePos(atom hf, atom dist, atom seektype)
  integer dMethod=20

        if seektype =3D SEEK_SET then dMethod =3D FILE_BEGIN
        elsif seektype =3D SEEK_CUR then dMethod =3D FILE_CURRENT
        elsif seektype =3D SEEK_END then dMethod =3D FILE_END
        end if
       =20
    return c_func(xSetFilePointer,{hf,dist,NULL,dMethod})
end function
atom PFNSEEK

id =3D routine_id("SetFilePos")=20
PFNSEEK =3D call_back(id)

atom PFNCLOSE PFNCLOSE=3D0
function CloseFile(atom handle)

   if handle =3D PFNCLOSE+96 then
      return 0
   elsif handle !=3D 0 then
      return c_func(xCloseHandle,{handle})
   end if

end function

id =3D routine_id("CloseFile")=20
PFNCLOSE =3D call_back(id)

constant cpuUNKNOWN =3D -1,
         cpu80286 =3D 0,=20
         cpu80386 =3D 1


--typedef struct {
constant erfOper =3D 0,
         erfType =3D 4,
         fError =3D 8


atom ERF
ERF =3D myalloc(12)

mypoke4(ERF + erfOper, 222)
mypoke4(ERF + erfType, 222)=20
mypoke4(ERF + fError, 222)

  =20
atom hfdi

hfdi =3D c_func(xFDICreate,{PFNALLOC, -- MACHINE LEVEL CRASH HERE!
                          PFNFREE,
                          PFNOPEN,
                          PFNREAD,
                          PFNWRITE,
                          PFNCLOSE,
                          PFNSEEK,
                          cpuUNKNOWN,
                          ERF})

junk =3D peek4u(ERF + erfOper) -- NO ERRORS if all are -> 222
junk =3D peek4u(ERF + erfType)=20
junk =3D peek4u(ERF + fError)

-- FDICABINETINFO - Information about a cabinet
constant
      cbCabinet =3D 0,              --// Total length of cabinet file
      cFolders =3D 4,               --// Count of folders in cabinet
      cFiles =3D 6,                 --// Count of files in cabinet
      setID =3D 8,                  --// Cabinet set ID
      iCabinet =3D 10,              --// Cabinet number in set (0 based)
      fReserve =3D 12,              --// TRUE =3D> RESERVE present in =
cabinet
      hasprev =3D 16,               --// TRUE =3D> Cabinet is chained =
prev
      hasnext =3D 20                --// TRUE =3D> Cabinet is chained =
next

atom pfdici
pfdici =3D myalloc(24)

atom hf
hf =3D CreateFile("sdkinst.cab","rb") --open " " cab file

if hf <=3D 0 then
   c_proc(xFDIDestroy,{hfdi})
   junk =3D CloseFile(hf)
   abort(0)
end if

junk =3D c_func(xFDIIsCabinet,{hfdi, hf, pfdici})

if junk =3D 0 then
   c_proc(xFDIDestroy,{hfdi})
   junk =3D CloseFile(hf)
end if
  =20
junk =3D myfree(ERF)
------=_NextPart_000_0009_01C30D99.5528CB00
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1170" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hello all,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have been waiting to implement Cab =
file wrappers=20
(Cabinet.dll)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I thought once Robert C. had made cdecl =
available=20
to us</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>that I could whip-up a working set but, =
I am=20
totally confused about</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>this very mysterious .dll</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Here is code I have tried (below), I =
have also=20
tried fptr.e by Matt Lewis</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>and&nbsp;code published by mic and none =
have=20
worked. Perhaps this should</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>work before Robert C. post 2.4 =
final?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I hope someone will guide me in the =
correct=20
direction if it's even possible.</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *look =
for --=20
MACHINE LEVEL CRASH HERE!*<BR></DIV></FONT>
<DIV><FONT face=3DArial size=3D2>&lt;code by Euman 2003&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>with trace</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>include dll.e<BR>include =
misc.e</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>integer xHeapCreate, xHeapDestroy, =
xHeapAlloc,=20
xHeapFree, <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xCreateFile,=20
xReadFile, xWriteFile, xSetFilePointer,=20
xCloseHandle,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xFDICreate,=20
xFDIIsCabinet, xFDICopy,=20
xFDIDestroy<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>procedure=20
not_found(sequence name)<BR>&nbsp;&nbsp;&nbsp; puts(1, "Couldn't find " =
&amp;=20
name &amp; '\n')<BR>&nbsp;&nbsp;&nbsp; abort(1)<BR>end =
procedure</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>function link_c_func(atom dll, sequence =
name,=20
sequence args, atom result)<BR>&nbsp;integer handle</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp; handle =3D =
define_c_func(dll, name,=20
args, result)<BR>&nbsp;&nbsp; if handle =3D -1=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; not_found(name)<BR>&nbsp;&nbsp;=20
else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return handle<BR>&nbsp;&nbsp; end =

if<BR>end function</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>function link_c_proc(atom dll, sequence =
name,=20
sequence args)<BR>&nbsp;integer handle<BR>&nbsp;&nbsp; handle =3D=20
define_c_proc(dll, name, args)<BR>&nbsp;&nbsp; if handle =3D -1=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; not_found(name)<BR>&nbsp;&nbsp;=20
else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return handle<BR>&nbsp;&nbsp; end =

if<BR>end function</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>procedure link_dll_routines()<BR>&nbsp; =
atom=20
kernel32, cabinet<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; kernel32 =
=3D=20
open_dll("kernel32.dll")<BR>&nbsp;&nbsp;&nbsp; if kernel32 =3D NULL=20
then<BR>&nbsp;not_found("kernel32.dll")<BR>&nbsp;&nbsp;&nbsp; end=20
if&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; cabinet =3D=20
open_dll("cabinet.dll")<BR>&nbsp;&nbsp;&nbsp; if cabinet =3D NULL=20
then<BR>&nbsp;not_found("cabinet.dll")<BR>&nbsp;&nbsp;&nbsp; end=20
if&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; xHeapCreate =3D=20
link_c_func(kernel32,"HeapCreate",{C_LONG,C_LONG,C_LONG},C_LONG)<BR>&nbsp=
;&nbsp;&nbsp;=20
xHeapDestroy =3D=20
link_c_func(kernel32,"HeapDestroy",{C_LONG},C_LONG)<BR>&nbsp;&nbsp;&nbsp;=
=20
xHeapAlloc =3D=20
link_c_func(kernel32,"HeapAlloc",{C_LONG,C_LONG,C_LONG},C_LONG)<BR>&nbsp;=
&nbsp;&nbsp;=20
xHeapFree =3D=20
link_c_func(kernel32,"HeapFree",{C_LONG,C_LONG,C_LONG},C_LONG)</FONT></DI=
V>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; xCreateFile =3D=20
link_c_func(kernel32,"CreateFileA",{C_POINTER,C_LONG,C_LONG,C_POINTER,C_L=
ONG,C_LONG,C_INT},C_LONG)<BR>&nbsp;&nbsp;&nbsp;=20
xReadFile =3D=20
link_c_func(kernel32,"ReadFile",{C_INT,C_POINTER,C_UINT,C_POINTER,C_POINT=
ER},C_LONG)<BR>&nbsp;&nbsp;&nbsp;=20
xWriteFile =3D=20
link_c_func(kernel32,"WriteFile",{C_INT,C_POINTER,C_LONG,C_POINTER,C_POIN=
TER},C_LONG)<BR>&nbsp;&nbsp;&nbsp;=20
xSetFilePointer =3D=20
link_c_func(kernel32,"SetFilePointer",{C_LONG,C_LONG,C_POINTER,C_LONG},C_=
LONG)<BR>&nbsp;&nbsp;&nbsp;=20
xCloseHandle =3D =
link_c_func(kernel32,"CloseHandle",{C_LONG},C_LONG)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; xFDICreate =3D=20
link_c_func(cabinet,"FDICreate",{C_POINTER,C_POINTER,C_POINTER,C_POINTER,=
C_POINTER,C_POINTER,C_POINTER,C_INT,C_LONG},C_LONG)<BR>&nbsp;&nbsp;&nbsp;=
=20
xFDIIsCabinet =3D=20
link_c_func(cabinet,"FDIIsCabinet",{C_LONG,C_INT,C_POINTER},C_LONG)<BR>&n=
bsp;&nbsp;&nbsp;=20
xFDICopy =3D=20
link_c_func(cabinet,"FDICopy",{C_LONG,C_POINTER,C_POINTER,C_INT,C_POINTER=
,C_POINTER,C_INT},C_LONG)<BR>&nbsp;&nbsp;&nbsp;=20
xFDIDestroy =3D link_c_proc(cabinet,"FDIDestroy",{C_LONG})</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>end procedure</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial =
size=3D2>link_dll_routines()<BR>trace(1)<BR>integer=20
id<BR>object junk</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>constant =
HEAP_ZERO_MEMORY=3D#00000008<BR>&nbsp;=20
<BR>global atom pHeap<BR>pHeap =3D =
c_func(xHeapCreate,{0,16384,0})</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV><FONT face=3DArial =
size=3D2>
<DIV><BR>global function myalloc(atom size)<BR>&nbsp;&nbsp; return=20
c_func(xHeapAlloc,{pHeap,HEAP_ZERO_MEMORY,size})<BR>end function<BR>atom =

PFNALLOC</DIV>
<DIV>&nbsp;</DIV>
<DIV>id =3D routine_id("myalloc") <BR>PFNALLOC =3D call_back(id)</DIV>
<DIV>&nbsp;</DIV>
<DIV>global function myfree(atom pmem)<BR>&nbsp;&nbsp; return=20
c_func(xHeapFree,{pHeap,0,pmem})<BR>end function<BR>atom PFNFREE</DIV>
<DIV>&nbsp;</DIV>
<DIV>id =3D routine_id("myfree") <BR>PFNFREE =3D call_back(id)</DIV>
<DIV>&nbsp;</DIV>
<DIV>global procedure mypoke(atom mem, object s)<BR>&nbsp;&nbsp; =
poke(mem,=20
s)<BR>end procedure</DIV>
<DIV>&nbsp;</DIV>
<DIV>global procedure mypoke4(atom mem, object s)<BR>&nbsp;&nbsp; =
poke4(mem, s)=20
<BR>end procedure</DIV>
<DIV>&nbsp;</DIV>
<DIV>global function mypeek(object si)<BR>&nbsp;&nbsp; if integer(si)=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return=20
peek(si)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;=20
else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return peek({si[1],si[2]})=20
<BR>&nbsp;&nbsp; end if<BR>end function</DIV>
<DIV>&nbsp;</DIV>
<DIV>global function mypeek4s(object si)<BR>&nbsp;&nbsp; if integer(si)=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return peek4s(si) =
<BR>&nbsp;&nbsp;=20
else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return peek4s({si[1],si[2]})=20
<BR>&nbsp;&nbsp; end if<BR>end function</DIV>
<DIV>&nbsp;</DIV>
<DIV>global function mypeek4u(object si)<BR>&nbsp;&nbsp; if integer(si)=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return peek4u(si) =
<BR>&nbsp;&nbsp;=20
else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return peek4u({si[1],si[2]})=20
<BR>&nbsp;&nbsp; end if<BR>end function</DIV>
<DIV>&nbsp;</DIV>
<DIV>global function allocate_string2(sequence s)<BR>atom=20
mem<BR>&nbsp;&nbsp;&nbsp; mem =3D =
myalloc(length(s)+1)<BR>&nbsp;&nbsp;&nbsp;=20
mypoke(mem, s)<BR>&nbsp;&nbsp;&nbsp; return mem<BR>end function</DIV>
<DIV>&nbsp;</DIV>
<DIV>global constant GENERIC_READ&nbsp; =3D=20
#80000000,<BR>&nbsp;&nbsp;GENERIC_WRITE =3D=20
#40000000,<BR>&nbsp;&nbsp;FILE_ATTRIBUTE_NORMAL =3D =
#80,<BR>&nbsp;&nbsp;FILE_BEGIN=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =3D=20
0,<BR>&nbsp;&nbsp;FILE_CURRENT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
=3D=20
1,<BR>&nbsp;&nbsp;FILE_END&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
=3D 2,<BR>&nbsp;&nbsp;FILE_FLAG_WRITE_THROUGH&nbsp;&nbsp;&nbsp; =3D=20
#80000000,<BR>&nbsp;&nbsp;FILE_FLAG_OVERLAPPED&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;=20
=3D =
#40000000,<BR>&nbsp;&nbsp;FILE_FLAG_NO_BUFFERING&nbsp;&nbsp;&nbsp;&nbsp; =
=3D=20
#20000000,<BR>&nbsp;&nbsp;FILE_FLAG_RANDOM_ACCESS&nbsp;&nbsp;&nbsp; =3D=20
#10000000,<BR>&nbsp;&nbsp;FILE_FLAG_SEQUENTIAL_SCAN&nbsp; =3D=20
#8000000,<BR>&nbsp;&nbsp;FILE_FLAG_DELETE_ON_CLOSE&nbsp; =3D=20
#4000000,<BR>&nbsp;&nbsp;FILE_FLAG_BACKUP_SEMANTICS =3D=20
#2000000,<BR>&nbsp;&nbsp;FILE_FLAG_POSIX_SEMANTICS&nbsp; =3D=20
#1000000,<BR>&nbsp;&nbsp;CREATE_NEW&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp; =3D=20
1,<BR>&nbsp;&nbsp;CREATE_ALWAYS&nbsp;&nbsp;&nbsp;&nbsp; =3D=20
2,<BR>&nbsp;&nbsp;OPEN_EXISTING&nbsp;&nbsp;&nbsp;&nbsp; =3D=20
3,<BR>&nbsp;&nbsp;OPEN_ALWAYS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =3D=20
4,<BR>&nbsp;&nbsp;TRUNCATE_EXISTING =3D =
5,<BR>&nbsp;&nbsp;INVALID_HANDLE_VALUE =3D=20
-1<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;<BR>global function =
CreateFile(sequence fname,=20
sequence accmode)<BR>atom File, FileName <BR>&nbsp; FileName =3D=20
allocate_string2(fname)<BR>&nbsp; if compare(accmode,"rb")=3D0=20
then<BR>&nbsp;&nbsp;&nbsp; File =3D=20
c_func(xCreateFile,{FileName,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRI=
BUTE_NORMAL+<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
FILE_FLAG_SEQUENTIAL_SCAN,NULL})<BR>&nbsp; elsif =
compare(accmode,"wb")=3D0=20
then<BR>&nbsp;&nbsp;&nbsp; File =3D=20
c_func(xCreateFile,{FileName,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTR=
IBUTE_NORMAL+<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
FILE_FLAG_SEQUENTIAL_SCAN,NULL})<BR>&nbsp; end if<BR>&nbsp; junk =3D=20
myfree(FileName)<BR>&nbsp; return File<BR>end function<BR>atom =
PFNOPEN</DIV>
<DIV>&nbsp;</DIV>
<DIV>id =3D routine_id("CreateFile") <BR>PFNOPEN =3D call_back(id)</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;--WriteFile()<BR>&nbsp;--hFile (handle) obtained by =
CreateFile=20
<BR>&nbsp;--must have GENERIC_WRITE access</DIV>
<DIV>&nbsp;</DIV>
<DIV>atom writebytes<BR>writebytes =3D myalloc(4)</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>function WriteFile(atom hFile, atom lpBuffer, atom=20
nNumberOfBytesToWrite)<BR>&nbsp; return=20
c_func(xWriteFile,{hFile,lpBuffer,nNumberOfBytesToWrite,writebytes,0})<BR=
>end=20
function&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;=20
<BR>atom PFNWRITE</DIV>
<DIV>&nbsp;</DIV>
<DIV>id =3D routine_id("CreateFile") <BR>PFNWRITE =3D =
call_back(id)</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;--ReadFile()<BR>&nbsp;--hFile (handle) obtained by CreateFile =

<BR>&nbsp;--must have GENERIC_READ access</DIV>
<DIV>&nbsp;</DIV>
<DIV>atom readbytes<BR>readbytes =3D myalloc(4) --lpNumberOfBytesRead =
</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>function ReadFile(atom hFile, atom lpBuffer, atom=20
nNumberOfBytesToRead)<BR>&nbsp; return=20
c_func(xReadFile,{hFile,lpBuffer,nNumberOfBytesToRead,readbytes,0})<BR>en=
d=20
function<BR>atom PFNREAD</DIV>
<DIV>&nbsp;</DIV>
<DIV>id =3D routine_id("ReadFile") <BR>PFNREAD =3D call_back(id)</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>constant SEEK_SET =3D=20
0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;=20
--/* seek to an absolute position=20
*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SEEK_CUR =3D=20
1,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;=20
--/* seek relative to current position=20
*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SEEK_END =3D =
2&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </DIV>
<DIV>&nbsp;</DIV>
<DIV>function SetFilePos(atom hf, atom dist, atom seektype)<BR>&nbsp; =
integer=20
dMethod </DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if seektype =3D SEEK_SET =
then=20
dMethod =3D FILE_BEGIN<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
elsif=20
seektype =3D SEEK_CUR then dMethod =3D=20
FILE_CURRENT<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elsif =
seektype =3D=20
SEEK_END then dMethod =3D =
FILE_END<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
end if<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
<BR>&nbsp;&nbsp;&nbsp;=20
return c_func(xSetFilePointer,{hf,dist,NULL,dMethod})<BR>end =
function<BR>atom=20
PFNSEEK</DIV>
<DIV>&nbsp;</DIV>
<DIV>id =3D routine_id("SetFilePos") <BR>PFNSEEK =3D call_back(id)</DIV>
<DIV>&nbsp;</DIV>
<DIV>atom PFNCLOSE PFNCLOSE=3D0<BR>function CloseFile(atom handle)</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp; if handle =3D PFNCLOSE+96 =
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
return 0<BR>&nbsp;&nbsp; elsif handle !=3D 0=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return=20
c_func(xCloseHandle,{handle})<BR>&nbsp;&nbsp; end if</DIV>
<DIV>&nbsp;</DIV>
<DIV>end function</DIV>
<DIV>&nbsp;</DIV>
<DIV>id =3D routine_id("CloseFile") <BR>PFNCLOSE =3D call_back(id)</DIV>
<DIV>&nbsp;</DIV>
<DIV>constant cpuUNKNOWN =3D=20
-1,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cpu80286 =3D 0,=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cpu80386 =3D =
1</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>--typedef struct {<BR>constant erfOper =3D=20
0,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; erfType =3D=20
4,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fError =3D =
8</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>atom ERF<BR>ERF =3D myalloc(12)</DIV>
<DIV>&nbsp;</DIV>
<DIV>mypoke4(ERF + erfOper, 222)<BR>mypoke4(ERF + erfType, 222) =
<BR>mypoke4(ERF=20
+ fError, 222)</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp; <BR>atom hfdi</DIV>
<DIV>&nbsp;</DIV>
<DIV>hfdi =3D c_func(xFDICreate,{PFNALLOC, -- MACHINE LEVEL CRASH=20
HERE!<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;=20
PFNFREE,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;=20
PFNOPEN,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;=20
PFNREAD,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;=20
PFNWRITE,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;=20
PFNCLOSE,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;=20
PFNSEEK,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;=20
cpuUNKNOWN,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;=20
ERF})</DIV>
<DIV>&nbsp;</DIV>
<DIV>junk =3D peek4u(ERF + erfOper) -- NO ERRORS if all are -&gt; =
222<BR>junk =3D=20
peek4u(ERF + erfType) <BR>junk =3D peek4u(ERF + fError)</DIV>
<DIV>&nbsp;</DIV>
<DIV>-- FDICABINETINFO - Information about a=20
cabinet<BR>constant<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cbCabinet =3D=20
0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;=20
--// Total length of cabinet file<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
cFolders =3D=20
4,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;=20
--// Count of folders in cabinet<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
cFiles =3D=20
6,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;=20
--// Count of files in cabinet<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setID =
=3D=20
8,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
--// Cabinet set ID<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; iCabinet =3D=20
10,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;=20
--// Cabinet number in set (0 based)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
fReserve=20
=3D=20
12,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;=20
--// TRUE =3D&gt; RESERVE present in =
cabinet<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
hasprev =3D=20
16,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;=20
--// TRUE =3D&gt; Cabinet is chained =
prev<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
hasnext =3D=20
20&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;=20
--// TRUE =3D&gt; Cabinet is chained next</DIV>
<DIV>&nbsp;</DIV>
<DIV>atom pfdici<BR>pfdici =3D myalloc(24)</DIV>
<DIV>&nbsp;</DIV>
<DIV>atom hf<BR>hf =3D CreateFile("sdkinst.cab","rb") --open " =
"&nbsp;cab=20
file</DIV>
<DIV>&nbsp;</DIV>
<DIV>if hf &lt;=3D 0 then<BR>&nbsp;&nbsp;=20
c_proc(xFDIDestroy,{hfdi})<BR>&nbsp;&nbsp; junk =3D =
CloseFile(hf)<BR>&nbsp;&nbsp;=20
abort(0)<BR>end if</DIV>
<DIV>&nbsp;</DIV>
<DIV>junk =3D c_func(xFDIIsCabinet,{hfdi, hf, pfdici})</DIV>
<DIV>&nbsp;</DIV>
<DIV>if junk =3D 0 then<BR>&nbsp;&nbsp; =
c_proc(xFDIDestroy,{hfdi})<BR>&nbsp;&nbsp;=20
junk =3D CloseFile(hf)<BR>end if<BR>&nbsp;&nbsp; <BR>junk =3D=20

------=_NextPart_000_0009_01C30D99.5528CB00--

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu