Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2014
    Posts
    11

    Red face Unanswered: Help with 64 vs 32 bit VBA acesss: VarPtr

    Hi all,

    I tried to add PtrSafe into the declare Function. It works for that but for error for VarPtr "type missmatch" trying to change some Long var to Longptr and got others error. Anyone have other solutions/suggestions? Thanks much

    Code:
    Option Compare Database
    Option Explicit
    Public Type GUID
        Data1(16) As Byte
    End Type
    
    #If VBA7 Then
    
        Private Declare PtrSafe Function CoCreateGuid Lib "ole32.dll" (pGuid As GUID) As Long
        Private Declare PtrSafe Function StringFromGUID2 Lib "ole32.dll" (rguid As Any, ByVal lpstrClsId As Long, ByVal cbMax As Long) As Long
        Private Declare PtrSafe Function IIDFromString Lib "ole32.dll" (ByVal lpsz As String, ByVal lpiid As Long) As Long
    
    #Else
    
        Private Declare Function CoCreateGuid Lib "ole32.dll" (pGuid As GUID) As Long
        Private Declare Function StringFromGUID2 Lib "ole32.dll" (rguid As Any, ByVal lpstrClsId As Long, ByVal cbMax As Long) As Long
        Private Declare Function IIDFromString Lib "ole32.dll" (ByVal lpsz As String, ByVal lpiid As Long) As Long
    
    #End If
    
    
    Public Function CreateGUID() As String
        Dim sGUID   As String       'store result here
        Dim tGUID   As GUID         'get into this structure
        Dim bGuid() As Byte     'get formatted string here
        Dim lRtn    As Long
        Const clLen As Long = 50
        
        lRtn = CoCreateGuid(tGUID)
        If lRtn = 0 Then                              'use API to get the GUID
            bGuid = String(clLen, 0)
            lRtn = StringFromGUID2(tGUID, VarPtr(bGuid(0)), clLen)  'use API to format it
            If lRtn > 0 Then                                        'truncate nulls
                sGUID = Mid$(bGuid, 1, lRtn - 1)
            End If
            CreateGUID = sGUID
        Else
            Err.Raise 10, "CreateGUID", "CoCreateGuid() call Failed with Error #" & CStr(lRtn)
        End If
    End Function
    Last edited by sweetboy02125; 09-25-14 at 13:37.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Not sure whether it can help you or not (I don't have a machine whith 64 bit Office available right now), however there are some valuable pieces of information there: Office Talk: Working with VBA in the 32-bit and 64-bit Versions of Office 2010

    Among others, I noticed this:
    Code:
    ' Test whether you are using the 64-bit version of Office 2010.
    #If Win64 Then
       Declare PtrSafe Function GetTickCount64 Lib "kernel32" () As LongLong
    #Else
       Declare PtrSafe Function GetTickCount Lib "kernel32" () As Long
    #End If
    While you use:
    Code:
    #If VBA7 Then
    Have a nice day!

  3. #3
    Join Date
    Mar 2014
    Posts
    11
    Quote Originally Posted by Sinndho View Post
    Not sure whether it can help you or not (I don't have a machine whith 64 bit Office available right now), however there are some valuable pieces of information there: Office Talk: Working with VBA in the 32-bit and 64-bit Versions of Office 2010

    Among others, I noticed this:
    Code:
    ' Test whether you are using the 64-bit version of Office 2010.
    #If Win64 Then
       Declare PtrSafe Function GetTickCount64 Lib "kernel32" () As LongLong
    #Else
       Declare PtrSafe Function GetTickCount Lib "kernel32" () As Long
    #End If
    While you use:
    Code:
    #If VBA7 Then
    I googled and start degugging and found the solution

    Change Long to LongPtr then works. Thanks

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

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
  •