Re: [WIN] GetLogicalDrives returns drives NOT present
- Posted by CChris <christian.cuvier at agr?cultur?.gouv.fr> Jan 29, 2008
- 1134 views
Dan Moyer wrote: > > Dan Moyer wrote: > > > > <<SNIP>> > > > > > > > > Chris: > > > > I kinda thought *logical* drives might be at least part of the problem > > > > I'm > > > > having, but I don't think I can decipher/translate the C code. I'm > > > > wondering if there isn't some way to defeat the presentation of the > > > > error > > > > messages? I thought there is something along those line in Win32Lib? > > > > > > > > > > If what you get is a dialog box that allows you to continue executing > > > (yes/no/cancel), > > > then calling setWarning(0) before running your code will suppress it. I > > > must > > > say that it is not the recommended way... > > > > > > I'll try to find some time to post a translation of the code at MSDN. > > > Actually, > > > it's pretty simple: get all known volume strings, then retrieve all the > > > paths > > > for each of those strings. Because there are sequences of chars > > > everywhere, > > > the code isn't as short as you might exect at first, but... it may be > > > worth > > > to try again. > > > > > > </snip> > > > > > > CChris > > > > CChris, > > > > Thanks, but never mind, I found a "getVolumeInformation()" function > > in a set of includes by Austin Cathey in my system, although I haven't yet > > re-found it in contributions, where I must have got it from at some time. > > > > That's pretty much what you originally suggested I do! :) > > > > Thanks for the effort, though. > > > > Dan > > Oops, the "getVolumeInformation" was really by William Heimbigner, it used a > dll handling include that was by Austin Cathey, that's what confused me, > I thought they were both by the same person. > > Dan Try running this under exwc.exe, it works under XP Pro at work. No errors, hence no error handling. Lines may wrap:
include dll.e include machine.e constant k32=open_dll("kernel32.dll") if not k32 then crash_message("Couldn't find kernel32.dll; perhaps not running under Windows.") abort(1) end if constant glds=define_c_func(k32,"GetLogicalDriveStringsA",{C_LONG,C_POINTER},C_LONG) if glds=-1 then crash_message("The GetLogicalDriveStringsA API is available only under Win 2K Pro, XP or later") abort(1) end if constant all_string_sizes = c_func(glds,{0,0}) if not all_string_sizes then crash_message("GetLogicalDriveStringsA failed for some reason.") abort(1) end if -- retrieve all volume names atom void atom string_buffer string_buffer = allocate(all_string_sizes) void = c_func(glds,{all_string_sizes,string_buffer}) if not void then crash_message("GetLogicalDriveStringsA failed for some reason.") abort(1) end if constant strlen = define_c_func(k32,"lstrlenA",{C_POINTER},C_LONG) if strlen=-1 then crash_message("lstrlen could not be found. Perhaps this is an Unicode build of Windows.") abort(1) end if puts(1,"Known drives:\n") puts(1,repeat('=',13)&"\n\n") -- scan all volumes integer len_str while 1 do -- read array of volume names -- how long is the volume string? len_str = c_func(strlen,{string_buffer}) if not len_str then -- reached the end exit end if puts(1,peek({string_buffer,len_str})&"\n") -- next string_buffer += len_str+1 end while ?machine_func(26,0)
It gives me all available drives, some of them being mapped network drives, not listing the CD-ROM drive where there's no cd, not listing USB ports with nothing connected to it. CChris