WinCE CopyFile RAPI [英] WinCE CopyFile RAPI

查看:72
本文介绍了WinCE CopyFile RAPI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MODS:请将其转到更适当的论坛。   HOPEFULLY ONE WITH Better TAFFIC

MODS: PLEASE MOVE THIS TO A MORE APPROPRIATE FORUM.  HOPEFULLY ONE WITH BETTER TRAFFIC

 

我认为此代码可能有问题:

I think something may be wrong with this code:

 


			bytesread = localFile.Read(buffer, filepos, buffer.Length);
			while(bytesread > 0)
			{
				// move remote file pointer # of bytes read
				filepos += bytesread;

				// write our buffer to the remote file
				if(! Convert.ToBoolean(CeWriteFile(remoteFile, buffer, bytesread, ref byteswritten, 0)))
				{ // check for success
					CeCloseHandle(remoteFile);
                    throw new RAPIException("Could not write to remote file: " + RemoteFileName);
				}
				try
				{
					// refill the local buffer
					bytesread = localFile.Read(buffer, 0, buffer.Length);
				}
				catch(Exception)
				{
					bytesread = 0;
				}
			}

推荐答案

也许我不明白那个参数是什么是为...

maybe I don't understand what that parameter is for...

在我看来

bytesread = localFile.Read(buffer,0,buffer.Length);

bytesread = localFile.Read(buffer, 0, buffer.Length);

会一遍又一遍地读取相同的位置。

would read the same spot over and over.

啊,当我调用localfile.read< - 这会增加localfile本身的内部pos计数器。 (localFile.Position)

Ahhhh, when I call localfile.read <- that increments the internal pos counter of localfile itself. (localFile.Position)

以便解决这个问题。

 

下一个问题, 

next question, 

我是否正确地做到了这一点? 我还有另一种方法来检查剩余字节并将缓冲区更改为该数量:

am i doing this right in the first place?  I sawe another way to do that checks for remaining bytes and changes the buffer to that amount:

do {
	if (Information.UBound(bytFile) - TotalCopied > lBufferLen) {
		// Copy the next set of bytes
		lResult = CeWriteFile(lCeFileHandle, bytFile(BytePos), lBufferLen, lBytesWritten, 0L);

		TotalCopied = TotalCopied + lBytesWritten;
		// Unicode compensation.
		BytePos = BytePos + (lBufferLen / 2);
		Form1.Label6.Caption = "Bytes Copied: " + TotalCopied + " Down.";

		Form1.Label6.Refresh();
	} else {
		// Copy the remaining bytes if greater than 0
		lBufferLen = Information.UBound(bytFile) - TotalCopied;
		if (lBufferLen > 0) {
			// Copy remaining bytes at one time.
			lResult = CeWriteFile(lCeFileHandle, bytFile(BytePos), lBufferLen, lBytesWritten, 0L);

		}
		TotalCopied = TotalCopied + lBytesWritten;
		Form1.Label6.Caption = "Bytes Copied: " + TotalCopied + " Down.";

		Form1.Label6.Refresh();
		bDoLoop = false;
	}
} while bDoLoop;



$ VB


in VB:


        Do
            If UBound(bytFile) - TotalCopied > lBufferLen Then
                ' Copy the next set of bytes
                lResult = CeWriteFile(lCeFileHandle, bytFile(BytePos), _
                        lBufferLen, lBytesWritten, 0&)
                        
                TotalCopied = TotalCopied + lBytesWritten
                ' Unicode compensation.
                BytePos = BytePos + (lBufferLen \ 2)
                Form1.Label6.Caption = "Bytes Copied: " & _
                        TotalCopied & " Down."
                        
                Form1.Label6.Refresh
            Else
                ' Copy the remaining bytes if greater than 0
                lBufferLen = UBound(bytFile) - TotalCopied
                If lBufferLen > 0 Then
                    ' Copy remaining bytes at one time.
                    lResult = CeWriteFile(lCeFileHandle, _
                           bytFile(BytePos), lBufferLen, lBytesWritten, 0&)
 
                End If
                TotalCopied = TotalCopied + lBytesWritten
                Form1.Label6.Caption = "Bytes Copied: " & _
                        TotalCopied & " Down."
                        
                Form1.Label6.Refresh
                Exit Do
            End If
        Loop


这篇关于WinCE CopyFile RAPI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆