Results 1 to 8 of 8

Thread: __vbaCopyBytesZero, __vbaRecAssign and __vbaRecDestruct

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2018
    Posts
    59

    __vbaCopyBytesZero, __vbaRecAssign and __vbaRecDestruct

    Hi,

    Can anyone help me by citing examples of using the __vbaCopyBytesZero, __vbaRecAssign and __vbaRecDestruct functions?

    Thank you

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: __vbaCopyBytesZero, __vbaRecAssign and __vbaRecDestruct

    Thread moved from Codebank, which is for working snippets rather than questions. However, I'm not sure I moved the thread to the right place. I see those VBA portions, which makes me think Office, but that kind of function usage seems more like VB6, so here it is, for now. If I got it wrong, somebody please report it.
    My usual boring signature: Nothing

  3. #3
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,852

    Re: __vbaCopyBytesZero, __vbaRecAssign and __vbaRecDestruct

    Hey Shaggy,

    The translated version of this link (originally provided by The Trick) is an excellent read.

    It goes through how some of the things we typically think are backwards. For instance, we often think that VB came before VBA, but it's the opposite. In fact, apparently, the first Microsoft push was to get a macro basic running for Excel, and hence the "EB" we see on some of the API calls. EB=Excel Basic.

    Also, it explains why we can't remove the "Visual Basic for Applications" reference under Project->References.

    It's also a good read for explaining the merger between the BASIC language and a drag-and-drop IDE UI designer interface.

    Just Saying,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: __vbaCopyBytesZero, __vbaRecAssign and __vbaRecDestruct

    I knew that, actually, as I was using VBA in Excel prior to the standalone version coming out. My understanding, which I have never bothered looking into in any more detail, was that VB1-3 was one thing, VB4 followed on VBA for Excel, then VB5, and finally VB6. I went VBA->VB5->VB6, so I never dealt with VBefore5 other than VBA.
    My usual boring signature: Nothing

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: __vbaCopyBytesZero, __vbaRecAssign and __vbaRecDestruct

    That's an odd way of looking at things that distorts history.

    VB predates VBA. What you are seeing and misinterpreting is a refactoring that was done once the earlier macro languages in MS Office programs were ditched to migrate to Visual Basic technology. Excel didn't get VBA until Excel 5.0 in 1993.

  6. #6
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,852

    Re: __vbaCopyBytesZero, __vbaRecAssign and __vbaRecDestruct

    Say hennyere,

    Sorry for hijacking your thread. Trying to get back on topic, I suspect you know that those are API calls into the msvbvm60.dll. The __vbaCopyBytesZero is essentially analogous to the RtlZeroMemory found in the kernel.dll.

    And the __vbaRecAssign and __vbaRecDestruct calls seem to have something to do with creating and destroying strings.

    Regarding the destruction of strings, that will happen automatically when they fall out of scope in VB6. Regarding the creation of strings, that's just a simple declaration (Dim s As String).

    Now, there are times when I've only got a string pointer, and I'd like to create a string for it. Here's some code I occasionally use to do that:

    Code:
    
    Option Explicit
    '
    Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
    Private Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, lpWideCharStr As Any, ByVal cchWideChar As Long, lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpDefaultChar As String, ByVal lpUsedDefaultChar As Long) As Long
    '
    
    Public Function MakeStringFromUnicodezPtr(lpszW As Long) As String
        '   StringFromPtr, StrFromPtr, Ptr2Str <--- for search.
        ' Input is a pointer to a Unicode null terminated string.
        ' This is effectively a BSTR, but we may have cases where we only have the pointer (such as API returns).
        ' MsgBox MakeStringFromUnicodezPtr(strptr("asdf")) ' Just makes a copy.
        Dim s As String
        Const CP_ACP As Long = 0&
        '
        s = String$(lstrlenW(ByVal lpszW) * 2&, vbNullChar)
        WideCharToMultiByte CP_ACP, 0&, ByVal lpszW, -1, ByVal s, Len(s), 0&, 0&
        MakeStringFromUnicodezPtr = Left$(s, lstrlenW(StrPtr(s)))
    End Function
    
    

    I'm not sure if that helps you or not.

    Personally, I make very little direct use of the msvbvm60.dll. I do use the GetMem?/PutMem? calls. And I also make some use of the following, but that's about it:

    Code:
    
    Private Declare Function vbaObjSetAddref Lib "msvbvm60" Alias "__vbaObjSetAddref" (ByRef dstObject As Any, ByRef srcObjPtr As Any) As Long
    Private Declare Sub vbaObjAddref Lib "msvbvm60" Alias "__vbaObjAddref" (ByVal Ptr As IUnknown)
    Private Declare Function vbaObjSet Lib "msvbvm60" Alias "__vbaObjSet" (dstObject As Any, ByVal srcObjPtr As Long) As Long
    
    
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: __vbaCopyBytesZero, __vbaRecAssign and __vbaRecDestruct

    Quote Originally Posted by Elroy View Post
    And the __vbaRecAssign and __vbaRecDestruct calls seem to have something to do with creating and destroying strings.
    I don't think so.

    These most likely are for manipulating records. That's what VB and OLE call the largely obsolete UDT which was meant for record-based I/O in Basic back in the MS-DOS days before we had Jet databases to replace both that and ISAM. Legacy technology, though still usable in 1998 to help port old code forward.

    They seem to take two forms, both "anonymous" ones not defined in any typelib and full blown published OLE ones that are. These internal functions are probably needed for the anonymous variety.


    Hard to be sure though, they are not documented anywhere that I know of.
    Last edited by dilettante; Jul 19th, 2019 at 11:46 AM.

  8. #8
    Fanatic Member TTn's Avatar
    Join Date
    Jul 2004
    Posts
    685

    Re: __vbaCopyBytesZero, __vbaRecAssign and __vbaRecDestruct

    According to this wealth of knowledge:
    https://renenyffenegger.ch/notes/dev...msvbvm60/index
    vbaCopyBytes: similar to RtlMoveMemory although for non-overlapping memory only.
    vbaCopyBytesZero: vbaCopyBytes followed by zeroing out the source memory block with zeroes.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width