1. Re: What to do?
- Posted by Andy Kurnia <akur at GAMERZ.NET> Mar 03, 1998
- 699 views
- Last edited Mar 04, 1998
At 10:42 PM 3/2/98 -0500, Greg Harris wrote: Thanks. I already have C:\VB\WINAPI\WIN32API.TXT and thought of it after I moan about not having WIN32.HLP for a long time (d'oh!). So I came up with windos.e. I wrote a test program (alas, it's been deleted as well) and discover the return values But why can't I come up with a working GetFileSize, GetFileTime and SetFileTime? Why is there no ChangeDirectory or ChangeDrive API? Can anyone tell me the possible values for ShellExecute? PS. I made it using as few statements as possible. (Hence the "constant"s.) I still have to stay under 300 statements, I don't have enough money to register ;-( To Robert Craig: It would be great if open_dll() returns 0 under DOS32. Alas, it's not the case, so I have to drop an extra four commands (include machine.e, if platform() != WIN32 then, abort(1), end if). It would be even better to have block statements (like for, if, elsif, while, end while, end if, end for) be counted as a clause (i.e. not a statement). That is, "if xxx then" (and other ifs) costs 0 statements, and so is "end if" (and other ends). Also for "elsif". And also for "procedure..end procedure", "function..end function", "type..end type". Also for "without" and "with", and also for "include". Then it'll really be a STATEMENT count It'd also be great to have a standard procedure (which doesn't need to be "include"d), that takes one object and does nothing with it. It'll be easy to use functions while ignoring their return values then. It'll save me an "object" declaration as well. Compare: null({DeleteFile("c:\\autoexec.bat"), DeleteFile("c:\\config.sys"), DeleteFile("c:\\command.com")}) -- do not try this at home as to sequence x x = {DeleteFile("c:\\autoexec.bat"), DeleteFile("c:\\config.sys"), DeleteFile("c:\\command.com")} -- a nice way to save statement count Btw does the {,,} operator guarantee that it evaluates every object it has from left-to-right? What about & (sequence concatenator)? Enough talk -- here's my windos.e, just in case anyone needs it! (I believe RDS can work on a more complete version and have it available in Euphoria 2.0 final release, which means it'll be a standard .e that costs 0 statements in the count.) Why not windos.ew? I like *.e ... and do you think they call C-for-windows program *.cw? Nah. I also prefer *.ex for any platform, rather than *.ex/*.exw we have now. -- windos.e starts at the "include dll.e" line include dll.e include machine.e include misc.e if platform() != WIN32 then abort(1) end if constant kernel32_dll = open_dll("kernel32.dll"), shell32_dll = open_dll("shell32.dll") if find(0, {kernel32_dll, shell32_dll}) then abort(1) end if constant -- existing, new, failifexists iCopyFile = define_c_func(kernel32_dll, "CopyFileA", {C_POINTER, C_POINTER, C_INT}, C_INT), -- path, security iCreateDirectory = define_c_func(kernel32_dll, "CreateDirectoryA", {C_POINTER, C_POINTER}, C_INT), -- file iDeleteFile = define_c_func(kernel32_dll, "DeleteFileA", {C_POINTER}, C_INT), -- file iGetFileAttributes = define_c_func(kernel32_dll, "GetFileAttributesA", {C_POINTER}, C_INT), -- existing, new iMoveFile = define_c_func(kernel32_dll, "MoveFileA", {C_POINTER, C_POINTER}, C_INT), -- path iRemoveDirectory = define_c_func(kernel32_dll, "RemoveDirectoryA", {C_POINTER}, C_INT), -- file, attr iSetFileAttributes = define_c_func(kernel32_dll, "SetFileAttributesA", {C_POINTER, C_INT}, C_INT), -- hwnd, operation, file, parameters, directory, showcmd iShellExecute = define_c_func(shell32_dll, "ShellExecuteA", {C_INT, C_INT, C_INT, C_INT, C_INT, C_INT}, C_INT) if find(-1, {iCopyFile, iCreateDirectory, iDeleteFile, iGetFileAttributes, iMoveFile, iRemoveDirectory, iSetFileAttributes, iShellExecute}) then abort(1) end if global constant -- ShellExecute SW_HIDE = 0, SW_SHOWNORMAL = 1, SW_NORMAL = 1, SW_SHOWMINIMIZED = 2, SW_SHOWMAXIMIZED = 3, SW_MAXIMIZE = 3, SW_SHOWNOACTIVATE = 4, SW_SHOW = 5, SW_MINIMIZE = 6, SW_SHOWMINNOACTIVE = 7, SW_SHOWNA = 8, SW_RESTORE = 9, SW_SHOWDEFAULT = 10 -- return 1 = OK, 0 = fail global function CopyFile(sequence src, sequence dest, integer bfailifexists) atom psrc, pdest, rv psrc = allocate_string(src) pdest = allocate_string(dest) rv = c_func(iCopyFile, {psrc, pdest, bfailifexists}) free(psrc) free(pdest) return rv end function -- return 1 = OK, 0 = fail global function CreateDirectory(sequence path) atom ppath, rv ppath = allocate_string(path) rv = c_func(iCreateDirectory, {ppath, 0}) free(ppath) return rv end function -- return 1 = OK, 0 = fail global function DeleteFile(sequence file) atom pfile, rv pfile = allocate_string(file) rv = c_func(iDeleteFile, {pfile}) free(pfile) return rv end function -- return attr, -1 = fail; GetFileAttributes("\\") == 16 (directory) global function GetFileAttributes(sequence file) atom pfile, rv pfile = allocate_string(file) rv = c_func(iGetFileAttributes, {pfile}) free(pfile) return rv end function -- return 1 = OK, 0 = fail global function MoveFile(sequence src, sequence dest) atom psrc, pdest, rv psrc = allocate_string(src) pdest = allocate_string(dest) rv = c_func(iMoveFile, {psrc, pdest}) free(psrc) free(pdest) return rv end function -- return 1 = OK, 0 = fail global function RemoveDirectory(sequence path) atom ppath, rv ppath = allocate_string(path) rv = c_func(iRemoveDirectory, {ppath}) free(ppath) return rv end function -- return 1 = OK, 0 = fail global function SetFileAttributes(sequence file, atom attr) atom pfile, rv pfile = allocate_string(file) rv = c_func(iSetFileAttributes, {pfile, attr}) free(pfile) return rv end function -- return hInstance, 2 = not found, ...? global function ShellExecute(atom hw, sequence pgm, sequence arg, integer sw) atom ppgm, parg, hinst ppgm = allocate_string(pgm) parg = allocate_string(arg) hinst = c_func(iShellExecute, {hw, 0, ppgm, parg, 0, sw}) free(ppgm) free(parg) return hinst end function