H
huguozhi
Unregistered / Unconfirmed
GUEST, unregistred user!
function FilediskMount(DeviceNumber: String; DriveLetter: String; FileName: PChar; CdImage: Boolean): Word;<br>var<br> Device: THandle;<br> DeviceName: String;<br> VolumeName: String;<br> BytesReturned: DWord;<br> OpenFileInformation: OPEN_FILE_INFORMATION;<br> IOCTL_FILE_DISK_OPEN_FILE: DWord;<br>begin<br> VolumeName := '//./'+DriveLetter;<br><br> Device := CreateFile(<br> Pchar(VolumeName),<br> GENERIC_READ or GENERIC_WRITE,<br> FILE_SHARE_READ or FILE_SHARE_WRITE,<br> nil,<br> OPEN_EXISTING,<br> FILE_FLAG_NO_BUFFERING,<br> 0<br> );<br> if Device <> INVALID_HANDLE_VALUE then<br> begin<br> messagebox(0,'错误1!','出错',48);<br> Exit;<br> end;<br><br><br> if CDImage then<br> DeviceName := DEVICE_DIR_NAME+DEVICE_BASE_NAME+DEVICE_BASE_NAME+'Cd'+DeviceNumber<br> else<br> DeviceName := DEVICE_DIR_NAME+DEVICE_BASE_NAME+DEVICE_BASE_NAME+DeviceNumber;<br><br><br> if not (DefineDosDevice(DDD_RAW_TARGET_PATH, Pchar(DriveLetter), Pchar(DeviceName))) then<br> begin<br> messagebox(0,'盘符已在使用!','出错',48);<br> Exit;<br> end;<br> Device := CreateFile(<br> Pchar(VolumeName),<br> GENERIC_READ or GENERIC_WRITE,<br> FILE_SHARE_READ or FILE_SHARE_WRITE,<br> nil,<br> OPEN_EXISTING,<br> FILE_FLAG_NO_BUFFERING,<br> 0<br> <br> if Device = INVALID_HANDLE_VALUE then<br> begin<br> DefineDosDevice(DDD_REMOVE_DEFINITION, Pchar(DriveLetter), nil);<br> messagebox(0,'错误2!','出错',48);<br> Exit;<br> end;<br><br> //Allocmem(Sizeof(OpenFileInformation)+StrLen(FileName)+4);<br> Zeromemory(@OpenFileInformation,Sizeof(OPEN_FILE_INFORMATION)+Length(FileName) + 4);<br> StrPCopy(OpenFileInformation.FileName,'/??/'+FileName);<br> OpenFileInformation.FileNameLength := StrLen(OpenFileInformation.FileName);<br> OpenFileInformation.Read_Only := False;<br><br> IOCTL_FILE_DISK_OPEN_FILE := CTL_CODE(FILE_DEVICE_FILE_DISK, $800, METHOD_BUFFERED, FILE_READ_ACCESS or FILE_WRITE_ACCESS);<br> if not (DeviceIoControl(<br> Device,<br> IOCTL_FILE_DISK_OPEN_FILE,<br> @OpenFileInformation,<br> Sizeof(OpenFileInformation)+ OpenFileInformation.FileNameLength - 1,<br> nil,<br> 0,<br> BytesReturned,<br> nil<br> ))<br> then<br> begin<br> DefineDosDevice(DDD_REMOVE_DEFINITION, Pchar(DriveLetter), nil);<br> messagebox(0,'错误3!','出错',48);<br> Exit<br> end;<br> //ReallocMem();<br> CloseHandle(Device);<br><br>end;<br><br>以上函数可以编译通过,但执行会报错误,好像是指针没有释放。请高手解决。