■多光驱控制问题100分求解■

 所属目录:Java   |   类型:技术问答   |   时间:2007-05-21
 问题:

如果系统有两个光驱(getlogicaldrives怎么用请别再说了)  
   
  各位直接点:   弹出光驱g:怎么写  
                          弹出光驱h:怎么写  
   
  我用mcisendstring来作,但只能控制mci默认的一个光驱.  
  我搜索过了,没有什么好的例子.代码有点乱!  
  帮忙啊!!  
 

· 网友精彩回答:

发表者:james0001

知道怎么写了,也许明天会写好。

发表者:doodu

不知道   up

发表者:hotus

帮顶

发表者:pcwak

private   declare   function   mcisendcommand   lib   "winmm.dll"   alias   "mcisendcommanda"   (byval   wdeviceid   as   long,   byval   umessage   as   long,   byval   dwparam1   as   long,   byval   dwparam2   as   any)   as   long

发表者:james0001

不用   mci   的方法  
  直接调用   ejectcd(   光驱盘符字符串   )   来弹出光驱,如果成功则返回   true。  
  如:  
  ejectcd(   "g:\"   )   弹出光驱   g:  
  ejectcd(   "h"   )   弹出光驱   h:  
   
   
  option   explicit  
   
  private   const   trueapi   =   0&  
  private   const   falseapi   =   0&  
  private   const   nullapi   =   0&  
  private   const   invalid_handle_value   =   -1&  
  private   declare   function   getversion   lib   "kernel32"   ()   as   long  
  private   declare   sub   zeromemory   lib   "kernel32"   alias   "rtlzeromemory"   (dest   as   any,   byval   numbytes   as   long)  
  private   declare   function   getdrivetypea   lib   "kernel32"   (byval   ndrive   as   string)   as   long  
  private   declare   function   getdrivetypew   lib   "kernel32"   (byval   ndrive   as   long)   as   long  
  private   const   drive_cdrom   =   5&  
  private   declare   function   createfilea   lib   "kernel32"   (byval   lpfilename   as   string,   byval   dwdesiredaccess   as   long,   byval   dwsharemode   as   long,   byval   lpsecurityattributes   as   long,   byval   dwcreationdisposition   as   long,   byval   dwflagsandattributes   as   long,   byval   htemplatefile   as   long)   as   long  
  private   declare   function   createfilew   lib   "kernel32"   (byval   lpfilename   as   long,   byval   dwdesiredaccess   as   long,   byval   dwsharemode   as   long,   byval   lpsecurityattributes   as   long,   byval   dwcreationdisposition   as   long,   byval   dwflagsandattributes   as   long,   byval   htemplatefile   as   long)   as   long  
  private   const   generic_read   =   &h80000000  
  private   const   generic_write   =   &h40000000  
  private   const   file_share_read   =   &h1  
  private   const   file_share_write   =   &h2  
  private   const   open_existing   =   3  
  private   const   file_flag_delete_on_close   =   &h4000000  
  private   declare   function   closehandle   lib   "kernel32"   (byval   hobject   as   long)   as   long  
  private   declare   function   deviceiocontrol   lib   "kernel32"   (byval   hdevice   as   long,   byval   dwiocontrolcode   as   long,   lpinbuffer   as   any,   byval   ninbuffersize   as   long,   lpoutbuffer   as   any,   byval   noutbuffersize   as   long,   lpbytesreturned   as   long,   byval   lpoverlapped   as   long)   as   long  
  private   const   vwin32_dioc_dos_ioctl   as   long   =   1&  
  private   const   fsctl_lock_volume   as   long   =   &h90018  
  private   const   fsctl_unlock_volume   as   long   =   &h9001c  
  private   const   fsctl_dismount_volume   as   long   =   &h90020  
  private   const   ioctl_storage_media_removal   as   long   =   &h2d4804  
  private   type   prevent_media_removal  
      preventmediaremoval   as   byte  
  end   type  
  private   const   ioctl_storage_eject_media   as   long   =   &h2d4808  
  private   type   dioc_registers  
      reg_ebx   as   long  
      reg_edx   as   long  
      reg_ecx   as   long  
      reg_eax   as   long  
      reg_edi   as   long  
      reg_esi   as   long  
      reg_flags   as   long  
  end   type  
  private   const   carry_flag   as   long   =   &h1&  
  private   type   paramblock  
      boperation   as   byte  
      bnumlocks   as   byte  
  end   type  
   
  function   ejectcd(byval   strdrive   as   string)   as   boolean  
      dim   ldrive   as   long,   strtmp   as   string  
       
      ldrive   =   clng(asc(strdrive))   -   &h40&  
      if   (ldrive   >=   &h20&)   then   ldrive   =   ldrive   -   &h20&  
      if   (ldrive   <   1&)   or   (ldrive   >   26&)   then   exit   function  
      strtmp   =   chr(ldrive   +   &h40&)   &   ":\"  
       
      if   getversion()   and   &h80000000   then  
          if   getdrivetypea(strtmp)   =   drive_cdrom   then  
              ejectcd   =   ejectcdworker9x(ldrive)  
          end   if  
      else  
          if   getdrivetypew(strptr(strtmp))   =   drive_cdrom   then  
              ejectcd   =   ejectcdworkernt(ldrive)  
          end   if  
      end   if  
  end   function  
   
  private   function   ejectcdworkernt(byval   ldrive   as   long)   as   boolean  
      dim   hvol   as   long,   strtmp   as   string  
      strtmp   =   "\\.\"   &   chr(ldrive   +   &h40&)   &   ":"  
      hvol   =   createfilew(strptr(strtmp),   generic_read,   file_share_read   or   file_share_write,   _  
          nullapi,   open_existing,   0,   nullapi)  
      if   hvol   <>   invalid_handle_value   then  
          dim   lbytesret   as   long  
          if   deviceiocontrol(hvol,   fsctl_lock_volume,   byval   nullapi,   0,   _  
              byval   nullapi,   0,   lbytesret,   nullapi)   then  
              if   deviceiocontrol(hvol,   fsctl_dismount_volume,   byval   nullapi,   0,   _  
                  byval   nullapi,   0,   lbytesret,   nullapi)   then  
                  dim   pmrremoval   as   prevent_media_removal  
                  if   deviceiocontrol(hvol,   ioctl_storage_media_removal,   pmrremoval,   len(pmrremoval),   _  
                      byval   nullapi,   0,   lbytesret,   nullapi)   then  
                      if   deviceiocontrol(hvol,   ioctl_storage_eject_media,   byval   nullapi,   0,   _  
                          byval   nullapi,   0,   lbytesret,   nullapi)   then  
                          ejectcdworkernt   =   true  
                      end   if  
                  end   if  
              end   if  
              deviceiocontrol   hvol,   fsctl_unlock_volume,   byval   nullapi,   0,   _  
                  byval   nullapi,   0,   lbytesret,   nullapi  
          end   if  
          closehandle   hvol  
      end   if  
  end   function  
   
  private   function   ejectcdworker9x(byval   ldrive   as   long)   as   boolean  
      dim   hvwin32   as   long  
      hvwin32   =   createfilea("\\.\vwin32",   0,   0,   nullapi,   0,   file_flag_delete_on_close,   nullapi)  
      if   hvwin32   <>   invalid_handle_value   then  
          dim   regs   as   dioc_registers,   ldevcat   as   long,   lresult   as   long,   lbytesret   as   long  
          ldevcat   =   &h800  
  ejectcdworker9x_relockvolume:  
          zeromemory   regs,   len(regs)  
          regs.reg_eax   =   &h440d&  
          regs.reg_ebx   =   ldrive  
          regs.reg_ecx   =   ldevcat   or   &h4a&  
          lresult   =   deviceiocontrol(hvwin32,   vwin32_dioc_dos_ioctl,   _  
              regs,   len(regs),   regs,   len(regs),   lbytesret,   nullapi)  
          if   (lresult   <>   falseapi)   and   ((regs.reg_flags   and   carry_flag)   =   0&)   then  
              dim   pbblock   as   paramblock  
              pbblock.boperation   =   2&  
              zeromemory   regs,   len(regs)  
              regs.reg_eax   =   &h440d&  
              regs.reg_ebx   =   ldrive  
              regs.reg_ecx   =   &h848  
              regs.reg_edx   =   varptr(pbblock)  
              lresult   =   deviceiocontrol(hvwin32,   vwin32_dioc_dos_ioctl,   _  
                  regs,   len(regs),   regs,   len(regs),   lbytesret,   nullapi)  
              if   (lresult   <>   falseapi)   and   (((regs.reg_flags   and   carry_flag)   =   0&)   or   _  
                  ((regs.reg_eax   =   &hb0&)   or   (regs.reg_eax   =   &h1&)))   then  
                  dim   lct   as   long  
                  for   lct   =   1&   to   pbblock.bnumlocks  
                      pbblock.boperation   =   1  
                      lresult   =   deviceiocontrol(hvwin32,   vwin32_dioc_dos_ioctl,   _  
                          regs,   len(regs),   regs,   len(regs),   lbytesret,   nullapi)  
                      if   regs.reg_flags   and   carry_flag   then   lresult   =   falseapi  
                      if   lresult   =   falseapi   then   exit   for  
                  next  
                  if   lresult   then  
                      zeromemory   regs,   len(regs)  
                      regs.reg_eax   =   &h440d&  
                      regs.reg_ebx   =   ldrive  
                      regs.reg_ecx   =   &h849  
                      lresult   =   deviceiocontrol(hvwin32,   vwin32_dioc_dos_ioctl,   _  
                          regs,   len(regs),   regs,   len(regs),   lbytesret,   nullapi)  
                      if   (lresult   <>   falseapi)   and   ((regs.reg_flags   and   carry_flag)   =   0&)   then  
                          ejectcdworker9x   =   true  
                      end   if  
                  end   if  
              end   if  
              ldevcat   =   &h800  
  ejectcdworker9x_reunlockvolume:  
              zeromemory   regs,   len(regs)  
              regs.reg_eax   =   &h440d&  
              regs.reg_ebx   =   ldrive  
              regs.reg_ecx   =   ldevcat   or   &h6a&  
              lresult   =   deviceiocontrol(hvwin32,   vwin32_dioc_dos_ioctl,   _  
                  regs,   len(regs),   regs,   len(regs),   lbytesret,   nullapi)  
              if   ((lresult   =   falseapi)   or   ((regs.reg_flags   and   carry_flag)   <>   0&))   and   _  
                  (ldevcat   <>   &h4800)   then  
                  ldevcat   =   &h4800:   goto   ejectcdworker9x_reunlockvolume  
              end   if  
          elseif   ldevcat   <>   &h4800   then  
              ldevcat   =   &h4800:   goto   ejectcdworker9x_relockvolume  
          end   if  
          closehandle   hvwin32  
      end   if  
  end   function  
   
 

发表者:lsftest

自己去看:  
  http://www.vbaspnew.com/ziyuan/y/qt/mcd.zip

.
处理 SSI 文件时出错
© 2006-2008 All Rights Reserved