Announcement

Collapse
No announcement yet.

VB Copymem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • VB Copymem

    What is an appropriate substitution for CopyMem?
    This is gettign awefully complicated just to read an event log, but will be worth it for everyone when I'm done..

    (Still on the event log problem)

    Code:
    Dim rBuff As EVENTLOGRECORD
    Local eBuff() As Byte
    Local StrucLen      As Long
    
    Do While rBuff.RecordNumber < EvtRecNo
        ret = ReadEventLog(EventLogHwd, _
                           EvtReadFlags, _
                           rBuff.RecordNumber + 1, _
                           eBuff(0), 16384, rBytesRead, _
                           rBytesNeeded)
        If ret = 0 Then Exit Function
    
        eBytePointer = 0
        Do While eBytePointer < rBytesRead 
            CopyMem rBuff, eBuff(eBytePointer), StrucLen
    ------------------
    Scott
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

  • #2
    MoveMemory VARPTR(rBuff), VARPTR(eBuff(eBytePointer)), StrucLen

    P.S. Don't forget to give StrucLen a length

    ------------------
    Jim..
    [email protected]


    [This message has been edited by Jim Huguley (edited June 20, 2001).]
    Jim..

    Comment


    • #3
      Code:
      '----------------------------------------------------------------------------
      ' Tip from Lance Edmonds FEB/09/2001.
      ' A PowerBasic Replacement for the API CopyMemory() function
      '----------------------------------------------------------------------------
      SUB CopyMemoryPB(ByVal lpDest AS DWORD,ByVal lpSource AS DWORD,ByVal cbLength AS LONG)
          POKE$ lpDest, PEEK$(lpSource, cbLength)
      END SUB
      Best regards
      Jules
      www.rpmarchildon.com

      Comment


      • #4
        It would really be easier to use a string for the buffer, which would allow
        you to POKE$ or LSET the results into the structure.

        Mmm, Len(EVENTLOGRECORD) is probably not doing what you want. LEN is
        for variables: think Len(lpBuffer) here.

        pnMinNumberOfBytesNeeded does not need to be initialized. It's a
        returned value.

        This bit is not right:
        Code:
        ByVal VarPtr(pnBytesRead), _
        VarPtr(pnMinNumberOfBytesNeeded) )
        Skip the ByVal and VarPtr parts, you just need to pass the variables here.


        ------------------
        Tom Hanlin
        PowerBASIC Staff

        Comment


        • #5
          OK I think I have a working copy, had to modify even the working copy here.

          Question is, in the end, will I be able to say:

          Msgbox format$(lpBuffer.EventID)

          Or is it that I have to take each byte and do a Chr$() to it and then append it to a string and parse it?
          That is ugly, but if so, so be it...
          It'd be nice to have a use for that TYPE, would make life easier


          Scott

          ------------------
          Scott
          Scott Turchin
          MCSE, MCP+I
          http://www.tngbbs.com
          ----------------------
          True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

          Comment


          • #6
            Tom, Len(EVENTLOGRECORD) does work fine.

            The two byval(varptr)) for bytes read and bytes needed respectively are equivalents of passing the long int from basic.
            There are too many languages with different calling styles. The PB definition with the EVENTRECORD in the function prototype should be changed to allow any buffer pointer to be passed I believe. Scott, you can copy the 56 bytes (or whatever the defined length of the record is into the EVENTRECORD structure. The remaining pseudo members of the structure will need variables allocated to hold that data. Be cognizant of padding.

            Comment


            • #7
              Scott, once you've succeeded in stuffing the top part of the buffer into a
              variable of type EVENTLOGRECORD, you'll be able to access the individual
              members of that variable without further processing. It's all taken care of
              you by that CopyMem, POKE$, MoveMemory, LSET, or whatever equivalent is
              being done after the buffer is read.

              Ron, my point was that the second VARPTR in that call simply doesn't function,
              since the value is being passed BYREF, not BYVAL. There's no use in adding
              all that complication just to pass the parameter incorrectly!

              Using BYVAL VARPTR(whatever) does have the advantage of allowing you to override
              BYREF parameter types like EVENTLOGRECORD if you'd prefer to use something else--
              so it's not necessary to modify the declarations for this purpose.


              ------------------
              Tom Hanlin
              PowerBASIC Staff

              Comment

              Working...
              X