STDAPI_(BOOL) CeWriteFile( 
HANDLE hFile, 
LPCVOID lpBuffer, 
DWORD nNumberOfBytesToWrite, 
LPDWORD lpNumberOfBytesWritten, 
LPOVERLAPPED lpOverlapped );此函数在RAPI.Dll中.我试着声明:
Public Declare Function CeWriteFile Lib "rapi.dll" (ByVal hFile As Long, ByVal lpBuffer As Long, _
                                                    ByVal nNumberOfBytesToWrite As Long, _
                                                    ByVal lpNumberOfBytesWritten As Long, _
                                                    ByVal lpOverlapped As Long)CeWriteFile(remoteFile, varptr(buffer(0)), l, VarPtr(bytewritten), 0)还有其它方式,都提示写内存出错!哪位大侠看看怎么样才是正确的?

解决方案 »

  1.   

    C#中是这样声明的:
    [DllImport("rapi.dll", CharSet=CharSet.Unicode)]
    internal static extern int CeWriteFile(IntPtr hFile, byte[] lpBuffer, 
    int nNumberOfbytesToWrite, ref int lpNumberOfbytesWritten, int lpOverlapped);================业精于勤荒于嬉,形成于思毁于随=================如果再给我一次爱的机会,我会好好的珍惜!
      

  2.   

    SDK中的文档:
    CeWriteFile
    This function writes data to a file. CeWriteFile starts writing data to the file at the position indicated by the file pointer. After the write operation has been completed, the file pointer is adjusted by the number of bytes actually written. CeWriteFile is a RAPI that enables an application that is running on a desktop computer to make function calls on a Microsoft? Windows? CE–based device.STDAPI_(BOOL) CeWriteFile( 
    HANDLE hFile, 
    LPCVOID lpBuffer, 
    DWORD nNumberOfBytesToWrite, 
    LPDWORD lpNumberOfBytesWritten, 
    LPOVERLAPPED lpOverlapped );
    Parameters
    hFile 
    [in] Handle to the file to be written to. The file handle must have been created with GENERIC_WRITE access to the file. 
    lpBuffer 
    [in] Pointer to the buffer containing the data to be written to the file. 
    nNumberOfBytesToWrite 
    [in] Number of bytes to write to the file. 
    A value of zero specifies a null write operation. A null write operation does not write any bytes but does cause the time stamp to change. CeWriteFile does not truncate or extend the file. To truncate or extend a file, use the CeSetEndOfFile function. Named pipe write operations across a network are limited to 65,535 bytes. lpNumberOfBytesWritten 
    [out] Pointer to the number of bytes written by this function call. CeWriteFile sets this value to zero before doing any work or error checking. 
    lpOverlapped 
    [in] Unsupported; set to NULL. 
    Return Values
    Nonzero indicates success. Zero indicates failure. To get extended error information, call CeGetLastError. Res
    If part of the file is locked by another process and the write operation overlaps the locked portion, this function fails. Accessing the output buffer while a write operation is using the buffer may lead to corruption of the data written from that buffer. Applications must not read from, write to, reallocate, or free the output buffer that a write operation is using until the write operation completes.Requirements
    Smartphone Platforms: Smartphone 2002 and later
    OS Versions: Windows CE 3.0 and later
    Header: rapi.h
    Library: rapi.libSee Also
    CeCreateFile, CeReadFile, CeSetEndOfFile================业精于勤荒于嬉,形成于思毁于随=================如果再给我一次爱的机会,我会好好的珍惜!
      

  3.   

    既然lpNumberOfBytesWritten参数用来输出,你用byval就不太好了
    lpOverlapped应该为结构体,既然用不到,声明为any就可以了试试这样:
    Public Declare Function CeWriteFile Lib "rapi.dll" (ByVal hFile As Long,  lpBuffer As any, _
    ByVal nNumberOfBytesToWrite As Long, _
    lpNumberOfBytesWritten As Long, _
    ByVal lpOverlapped As any)调用:
    CeWriteFile(remoteFile, buffer(0), l, bytewritten, 0&)
      

  4.   

    Public Declare Function CeWriteFile Lib "rapi.dll" (ByVal hFile As Long,  lpBuffer As any, _
    ByVal nNumberOfBytesToWrite As Long, _
    lpNumberOfBytesWritten As Long, _
    ByVal lpOverlapped As any)
      

  5.   

    Public Declare Function CeWriteFile Lib "rapi.dll" (ByVal hFile As Long, lpBuffer As Any, _
                                                        ByVal nNumberOfBytesToWrite As Long, _
                                                        ByRef lpNumberOfBytesWritten As Long, _
                                                        ByVal lpOverlapped As Long)
    CeWriteFile(remoteFile, buffer(0), l, bytewritten, 0&)这样还是报错.ByVal lpNumberOfBytesWritten As Long,的时候,我传值是这样传的varptr(bytewritten).我在VB中的测试代码如下:
        Dim remoteFile As Long
        Dim ret As Long
        remoteFile = 0
        Dim RemoteFileName As String
        Dim strLocalfile As String
        Dim buff() As Byte                '4K缓冲
        strLocalfile = App.Path & "\Module1.bas"
        RemoteFileName = "\Temp\test.txt"
        Dim file() As Byte
        file = RemoteFileName
        Dim buffer() As Byte
        Dim bytesread As Long, bytewritten As Long, filepos As Long
        bytesread = 0
        bytewritten = 0
        filepos = 0
        If Init() <> 0 Then
            MsgBox "初始化错误!"
            Exit Sub
        End If
        remoteFile = CeCreateFile(StrPtr(RemoteFileName), GENERIC_WRITE, 0, 0, 2, FILE_ATTRIBUTE_NORMAL, 0)
        If remoteFile = INVALID_HANDLE_VALUE Then
            MsgBox "can't create remote file"
            GoTo Over
        Else
            MsgBox "create remote file success"
        End If
        Dim fileLength As Long
        fileLength = FileLen(strLocalfile)
        Open strLocalfile For Binary Access Read As #1
        Dim i As Integer
        i = (fileLength \ 4096)
        If i * 4096 < fileLength Then
            i = i + 1
        End If
        Dim k As Integer
        Dim l As Integer
        For k = 1 To i
            If k < i Then
                l = 4096
            Else
                l = fileLength - (k - 1) * 4096
            End If
            ReDim buffer(l)
            Get #1, , buffer
            strLocalfile = buffer
            ret = CeWriteFile(remoteFile, buffer(0), l, bytewritten, 0&)
            If ret = 0 Then
                MsgBox "写入文件错误!"
                GoTo Over
            End If
            If bytewritten <> l Then
                MsgBox "写入文件长度不对!"
                GoTo Over
            End If
        Next
    Over:
        Close #1
        CeCloseHandle (remoteFile)
        CeRapiUninit经理催了好几遍了,大侠帮忙!================业精于勤荒于嬉,形成于思毁于随=================如果再给我一次爱的机会,我会好好的珍惜!
      

  6.   

    Public Declare Function CeWriteFile Lib "rapi.dll" (ByVal hFile As Long, lpBuffer As Any, _
                                                        ByVal nNumberOfBytesToWrite As Long, _
                                                        ByRef lpNumberOfBytesWritten As Long, _
                                                        ByVal lpOverlapped As Any)这样声明了.还是不行.
    ================业精于勤荒于嬉,形成于思毁于随=================如果再给我一次爱的机会,我会好好的珍惜!
      

  7.   

    Public Declare Function CeWriteFile Lib "rapi.dll" _
                                                (ByVal hFile As Long, _
                                                lpBuffer As Any, _
                                                ByVal nNumberOfBytesToWrite As Long, _
                                                lpNumberOfBytesWritten As Long, _
                                                ByVal lpOverlapped As Long) As Long
    在国外的论坛找到是这样声明的.
    看来是我调用处有问题了!================业精于勤荒于嬉,形成于思毁于随=================如果再给我一次爱的机会,我会好好的珍惜!