Cabinet Files .cab

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

Hello all,

I left a post the other day that had a link to the Cabfile SDK.
Well, I started codeing it a few hours ago and I just dont have time to figure
out why the hek FDICreate allocates 2052 bytes then alloc's over 7 meg
then proceeds to read a file that hasnt even been created yet.

Could be I am overlooking some details that should occur before I setup
the FDI Context.

Anyway, here's the code I have if anyone wants to take over, otherwise it
may be a while before Im able to return to it.

Make sure to stick in a trace before hfdi (below)

Euman
euman at bellsouth.net

< CODE ... >

include dll.e

integer xHeapCreate, xHeapDestroy, xHeapAlloc, xHeapFree,
        xCreateFile, xReadFile, xWriteFile, xSetFilePointer, xCloseHandle,
        xFDICreate, xFDIIsCabinet, xFDICopy, xFDIDestroy

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 = define_c_func(dll, name, args, result)
   if handle = -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 = define_c_proc(dll, name, args)
   if handle = -1 then
      not_found(name)
   else
      return handle
   end if
end function

procedure link_dll_routines()
  atom kernel32, cabinet

    kernel32 = open_dll("kernel32.dll")
    if kernel32 = NULL then
 not_found("kernel32.dll")
    end if
    cabinet = open_dll("cabinet.dll")
    if cabinet = NULL then
 not_found("cabinet.dll")
    end if

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

xCreateFile =
    link_c_func(kernel32,"CreateFileA",{C_POINTER,C_LONG,C_LONG,C_POINTER,C_LONG,C_LONG,C_INT},C_LONG)
xReadFile =
    link_c_func(kernel32,"ReadFile",{C_INT,C_POINTER,C_LONG,C_POINTER,C_POINTER},C_LONG)
xWriteFile =
    link_c_func(kernel32,"WriteFile",{C_INT,C_POINTER,C_LONG,C_POINTER,C_POINTER},C_LONG)
xSetFilePointer =
    link_c_func(kernel32,"SetFilePointer",{C_LONG,C_LONG,C_POINTER,C_LONG},C_LONG)
    xCloseHandle = link_c_func(kernel32,"CloseHandle",{C_LONG},C_LONG)

    xFDICreate =
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 =
    link_c_func(cabinet,"FDIIsCabinet",{C_LONG,C_INT,C_POINTER},C_LONG)
xFDICopy =
    link_c_func(cabinet,"FDICopy",{C_LONG,C_POINTER,C_POINTER,C_INT,C_POINTER,C_POINTER,C_INT},C_LONG)
    xFDIDestroy = link_c_func(cabinet,"FDIDestroy",{C_LONG},C_INT)

end procedure

link_dll_routines()

object junk

constant HEAP_ZERO_MEMORY=#00000008

global atom pHeap
pHeap = c_func(xHeapCreate,{0,16384,0})

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

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

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

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

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

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

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

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

constant GENERIC_READ =  #80000000,
         GENERIC_WRITE =  #40000000,
         FILE_SHARE_READ = 1,
         FILE_SHARE_WRITE = 2,
         OPEN_EXISTING = 3

function CreateFile(sequence lpFileName, atom dwDesiredAccess, atom dwShareMode,
atom lpSecurityAttributes,
atom dwCreationDisposition, atom dwFlagsAndAttributes, atom
                    hTemplateFile)
 atom File, FileName

  FileName = allocate_string2(lpFileName)

  --needs code to check flags specifically DesiredAccess
  --here!

File =
  c_func(xCreateFile,{FileName,dwDesiredAccess,dwShareMode,lpSecurityAttributes,
dwCreationDisposition,dwFlagsAndAttributes,hTemplateFile })

  junk = myfree(FileName)

 return File
end function


function ReadFile(atom hFile, atom lpBuffer, atom nNumberOfBytesToRead,atom
lpNumberOfBytesRead,atom lpOverlapped)
 atom File

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

return
  c_func(xReadFile,{hFile,lpBuffer,nNumberOfBytesToRead,lpNumberOfBytesRead,lpOverlapped})

 --return File
end function

function WriteFile(atom hFile, atom lpBuffer, atom nNumberOfBytesToWrite, atom
lpNumberOfBytesWritten, atom lpOverlapped)
 atom File

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

return
  c_func(xWriteFile,{hFile,lpBuffer,nNumberOfBytesToWrite,lpNumberOfBytesWritten,lpOverlapped})

end function

function CloseFile(atom handle)
    return c_func(xCloseHandle,{handle})
end function

function SetFilePos( )
-- to do
   return 0
end function

constant cpuUNKNOWN = -1,
         cpu80286 = 0,
         cpu80386 = 1

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

atom ERF
ERF = myalloc(12)

global atom PFNALLOC,PFNFREE,PFNOPEN,PFNREAD,PFNWRITE,PFNCLOSE,PFNSEEK
   PFNALLOC = call_back(routine_id("myalloc"))
   PFNFREE = call_back(routine_id("myfree"))
   PFNOPEN = call_back(routine_id("CreateFile"))
   PFNREAD = call_back(routine_id("ReadFile"))
   PFNWRITE = call_back(routine_id("WriteFile"))
   PFNCLOSE = call_back(routine_id("CloseFile"))
   PFNSEEK = call_back(routine_id("SetFilePos"))

atom hfdi
hfdi =
c_func(xFDICreate,{PFNALLOC,PFNFREE,PFNOPEN,PFNREAD,PFNWRITE,PFNCLOSE,PFNSEEK,cpuUNKNOWN,ERF})

myfree(ERF)

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

Search



Quick Links

User menu

Not signed in.

Misc Menu