• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

32bit file to run in 64bit

Pugazh

New Member
I get a error message when i run a .xlsm file when i open the file. some of the cells are showing errors. screen shot attached.
 

Attachments

  • XLSM file to run in 64 bit.JPG
    XLSM file to run in 64 bit.JPG
    119.4 KB · Views: 11
All the Function names must start with

Private Declare Ptrsafe Function FunctionName

instead of

Private Declare Function FunctionName
 
Last edited:
Dear Hui,
after changing "Private Ptrsafe Declare Function FunctionName" i get this message (see attached file)
upload_2019-1-17_0-0-42.png
 

Attachments

  • 01 XLSM file to run in 64 bit.JPG
    01 XLSM file to run in 64 bit.JPG
    164.7 KB · Views: 4
It should be "Declare PtrSafe". NOT "PtrSafe Declare".

Go through the link I gave, as declaring function as PtrSafe may not be enough in some cases. Such as when variable is 32 bit, it may also need to be declared as 64 bit (LongPtr).
 
Dear CHihiro, Can you please help on this.

Code:
Option Explicit

Private Declare PtrSafe Function SHBrowseForFolder Lib "shell64" _
   (lpbi As BROWSEINFO) As LongPtr
Private Declare PtrSafe Function SHGetPathFromIDList Lib "shell64" _
   (ByVal pidList As LongPtr, ByVal lpBuffer As String) As LongPtr
Private Declare PtrSafe Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As LongPtr)
Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" _
   (ByVal hWnd As LongPtr, ByVal wMsg As LongPtr, ByVal wParam As LongPtr, _
lParam As Any) As LongPtr
Private Declare PtrSafe Function SHSimpleIDListFromPath Lib "shell32" Alias "#162" _
   (ByVal szPath As String) As LongPtr
Private Const BIF_RETURNONLYFSDIRS As Long = 1
Private Const BIF_DONTGOBELOWDOMAIN As Long = 2
Private Const BFFM_INITIALIZED As Long = 1
Private Const MAX_PATH As Long = 260
Private Const WM_USER As Long = &H400
Private Const BFFM_SETSTATUSTEXTA As Long = (WM_USER + 100)
Private Const BFFM_SETSELECTIONA As Long = (WM_USER + 102)
Private Const BFFM_SETSELECTIONW As Long = (WM_USER + 103)
Private Const BFFM_SETSTATUSTEXTW As Long = (WM_USER + 104)
Private Type BROWSEINFO
   hwndOwner As LongPtr
   pidlRoot As LongPtr
   pszDisplayName As String
   lpszTitle As String
   ulFlags As Long
   lpfnCallback As Long
   lParam As Long
   iImage As Long
End Type
' Callback für die Browse-Directory-Methode - "pidList"-Methode
' zur Verwendung in der BrowseDirectory()-Funktion

Private Function BrowseCallBackProc(ByVal hWnd As Long, _

End Function
        ByVal uMsg As Long, ByVal lParam As Long, _
        ByVal lpData As Long) As Long
    'Voreinstellung des Verzeichnisses im Verzeichnis-
    'Dialog unter Verwendung des Parameters "pidList"
    Select Case uMsg
    Case BFFM_INITIALIZED
        Call SendMessage(hWnd, BFFM_SETSELECTIONA, False, ByVal lpData)
    Case Else
    End Select
End Function



' Dummy-Methode, um den Inhalt des AddressOf-Operators zu erhalten und
' zur Verwendung in der BrowseDirectory()-Funktion zurückzugeben

Private Function FARPROC(pfn As Long) As Long

End Function
    'Einstellen und Erhalten der Adresse für ein Callback. Das ist notwendig,
    'weil man "AddressOf" nicht direkt einem benutzerdefinierten Typ zuweisen
    'kann. Man kann es aber einer anderen Variablen vom Typ "Long" zuweisen,
    'der - wie hier auch von der Function zurückgegeben - weiter verwendet
    'werden kann.
    FARPROC = pfn
End Function



' "pidList"-Parameter für den vorgegebenen Pfad wird durch den Aufruf
' der undokumenteierten API-Funktion #162 zurückgegeben.

Private Function GetPIDLFromPath(ByVal sPath As String) As Long

End Function
    'If IsWinNT Then
        GetPIDLFromPath = SHSimpleIDListFromPath(StrConv(sPath, vbUnicode))
    'Else
    '    GetPIDLFromPath = SHSimpleIDListFromPath(sPath)
    'End If
End Function



Public Function BrowseDirectory(Optional ByVal strInitialDir As String, _
   Optional ByVal _
   hWnd As Long) As String
   Dim lpIDList As Long
   Dim sBuffer As String
   Dim szTitle As String
   Dim tBrowseInfo As BROWSEINFO
   szTitle = "Bitte wählen Sie einen Ordner aus!"
   With tBrowseInfo
      .hwndOwner = hWnd
      .pidlRoot = 0
      .lpszTitle = szTitle
      ' .ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
      .lpfnCallback = FARPROC(AddressOf BrowseCallBackProc)
      .lParam = GetPIDLFromPath(strInitialDir)
   End With
   lpIDList = SHBrowseForFolder(tBrowseInfo)
   If (lpIDList) Then
      sBuffer = Space(MAX_PATH)
      SHGetPathFromIDList lpIDList, sBuffer
      sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
      BrowseDirectory = sBuffer
      ' Ressourcen freigeben
      CoTaskMemFree lpIDList
   Else
      BrowseDirectory = strInitialDir
   End If
   ' Ressourcen freigeben
   CoTaskMemFree tBrowseInfo.lParam
End Function
Public Function OrdnerAuswahl2()
   Dim strInitialDir As String, strPath As String
    'Verzeichnisdialog mit Voreinstellung anzeigen
    strInitialDir = "D:\Eigene Dateien\Visio\peguform\"
    strPath = BrowseDirectory(strInitialDir)
  
   OrdnerAuswahl2 = strPath
   'strPath = BrowseDirectory()
End Function

' -- entnommen: http://www.herber.de/forum/archiv/276to280/t277517.htm
 
Last edited by a moderator:
You may well be getting issues that you are referencing 32bit libraries that are not necessarily available on a 64 bit machine

I would ask whom ever made the file to advise you
 
Pugazh
How do You copy & paste these?

... expected: end of statement ...

Seems something new ... again ...
Do this Function has ... or try to have two End Function's?
Screenshot 2019-01-17 at 13.24.27.png
... there are few more as above ... hmm?
 
ByVal should remain as Long.
Ex: Below should be Long
Code:
ByVal pidList As LongPtr
Also function itself should be Long and not LongPtr. At a glance, didn't see any pointer/handles in first few declaration that needed to LongPtr.

However, it's difficult to test things without sample workbook. If you need further help, I'd recommend that you upload sample workbook along with complete module/code.
 
Back
Top