我想实现类似这样c函数的功能
void cfunction(int startAddress, int length)
{
    *(startAddress+length)=0x48;
}
而对应的vb函数:
外面有一个byte数组,现在要通过程序将该数组第length个元素置成0x80
private sub vbFunction(byval startAddress as byte, byval length as integer)end sub
函数体中间应怎么写呢?

解决方案 »

  1.   

    没有用过:这样试一下:
    private sub vbFunction(byval startAddress as byte(), byval length as integer)
    startAddress(length)=&h48 或 startAddress(length-1)=&h48 
    end sub
      

  2.   

    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal length As Long)
    Private Sub vbFunction(ByVal startAddress As Byte, ByVal length As Integer)
    Dim nValue As Integer
    nValue = &H48
    CopyMemory ByVal (startAddress + length), nValue, LenB(nValue)
    End Sub
      

  3.   

    上面写错了 不好意思
    Private Sub vbFunction(startAddress As Byte, ByVal length As Integer)
    Dim nValue As Integer
    nValue = &H48
    CopyMemory ByVal (VarPtr(startAddress) + length), nValue, LenB(nValue)
    End Sub
    我没试过 不行的话发消息给我
      

  4.   

    搞好了,应该是CopyMemory ByVal (VarPtr(startAddress) + length), varptr(nValue), LenB(nValue)
      

  5.   

    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal length As Long)Private Sub vbFunction(ByVal startAddress As Long, ByVal length As Long)
        Dim nValue As Integer
        nValue = &H48
        CopyMemory ByVal (startAddress + length), nValue, 1
    End SubPrivate Sub Form_Load()
        Dim b(80) As Byte
        vbFunction VarPtr(b(0)), 4
    End Sub