none
Windows 8.1\Office 2013 (64x) Code crashes Word RRS feed

  • Question

  • Hi,

    I have a template add-in that I developed in Windows 2007\Word 2010 (32x).  It works fine on my PC with Office 2013 (32x) as well.  A user with Windows 8.1 Office 2013 (64x) reports it is crashing Word.  I don't have Office 2013 (64x) to test with but working with the user, I've been able to isolate the cause of the crash to a particular module.  The purpose of the module is to return the path of the users Windows personal folder.  Run the Sub Test to demo.  I've commented in the function where the user reports the crash occurs.

    I suspect the problem is in my conditional code statements, but I don't know how to fix it.  Hopefully someone reading this has Windows 8.1/Office 2013 (64x) can identify the problem.  Thank you. 

    Option Explicit #If VBA7 Then Public Declare PtrSafe Function SHGetSpecialFolderLocation _ Lib "shell32" (ByVal hwnd As Long, _ ByVal nFolder As Long, ppidl As Long) As Long Public Declare PtrSafe Function SHGetPathFromIDList _ Lib "shell32" Alias "SHGetPathFromIDListA" _ (ByVal Pidl As Long, ByVal pszPath As String) As Long Public Declare PtrSafe Sub CoTaskMemFree Lib "ole32" (ByVal pvoid As Long) #Else Public Declare PtrSafe Function SHGetSpecialFolderLocation _ Lib "shell32" (ByVal hwnd As Long, _ ByVal nFolder As Long, ppidl As Long) As Long Public Declare PtrSafe Function SHGetPathFromIDList _ Lib "shell32" Alias "SHGetPathFromIDListA" _ (ByVal Pidl As Long, ByVal pszPath As String) As Long Public Declare PtrSafe Sub CoTaskMemFree Lib "ole32" (ByVal pvoid As Long) #End If Public Const CSIDL_PERSONAL = &H5 Public Const CSIDL_DESKTOPDIRECTORY = &H10 Public Const MAX_PATH = 260 Public Const NOERROR = 0

    Sub Test() Dim strFilePath strFilePath = SpecFolder(CSIDL_PERSONAL) & "\QuickList.docx" MsgBox strFilePath End Sub Public Function SpecFolder(ByVal lngFolder As Long) As String Dim lngPidlFound As Long Dim lngFolderFound As Long Dim lngPidl As Long Dim strPath As String strPath = Space(MAX_PATH) lngPidlFound = SHGetSpecialFolderLocation(0, lngFolder, lngPidl) 'Word crashes on this line. If lngPidlFound = NOERROR Then lngFolderFound = SHGetPathFromIDList(lngPidl, strPath) If lngFolderFound Then SpecFolder = Left$(strPath, _ InStr(1, strPath, vbNullChar) - 1) End If End If CoTaskMemFree lngPidl End Function



    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Tuesday, January 20, 2015 10:31 PM

All replies

  • Hi Greg Maxey,

    As far as I tested, the code works well for me. My test environment is Win 7 64-bit and Office 2013 64-bit.

    Based on the code, you are developing with VBA, I would like to move it to VBA forum to get more effective response.

    Also since the issue may relative to the Windows API invoke, I also suggest that you to reopen a new thread in General Windows Desktop Development Issues forum.

    Regards & Fei 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, January 21, 2015 3:32 AM
    Moderator
  • Fei,

    Thanks.  Maybe the issue is the user Windows 8.1. 

    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Wednesday, January 21, 2015 3:59 AM
  • Re:  32bit vs. 64bit declarations

    For what it is worth, my limited understanding of the subject is that PtrSafe is not used with 32bit (#Else) declarations.
    '---

    Jim Cone
    Portland, Oregon USA
    https://goo.gl/IUQUN2 (Dropbox)
    (free & commercial excel add-ins & workbooks)

    • Edited by James Cone Sunday, October 30, 2016 7:38 PM
    Wednesday, January 21, 2015 6:18 AM
  • Try

    #If Win64 Then
      Public Declare PtrSafe Function SHGetSpecialFolderLocation _
        Lib "shell32" (ByVal hwnd As Long, _
        ByVal nFolder As Long, ppidl As Long) As Long
    
      Public Declare PtrSafe Function SHGetPathFromIDList _
        Lib "shell32" Alias "SHGetPathFromIDListA" _
        (ByVal Pidl As Long, ByVal pszPath As String) As Long
    
      Public Declare PtrSafe Sub CoTaskMemFree Lib "ole32" (ByVal pvoid As Long)
    #Else
       Public Declare Function SHGetSpecialFolderLocation _
        Lib "shell32" (ByVal hwnd As Long, _
        ByVal nFolder As Long, ppidl As Long) As Long
    
       Public Declare Function SHGetPathFromIDList _
         Lib "shell32" Alias "SHGetPathFromIDListA" _
        (ByVal Pidl As Long, ByVal pszPath As String) As Long
    
       Public Declare Sub CoTaskMemFree Lib "ole32" (ByVal pvoid As Long)
    #End If





    Wednesday, January 21, 2015 10:50 AM
  • Graham,

    I'll pass the this change on to the user experiencing the problem and if it works for him I'll let you know.  Thanks.


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Wednesday, January 21, 2015 1:24 PM
  • Jim,

    Yes I agree.  Looking at my original project that is apparently the results of some changes passed back and forth between me and the user having the problem.  They don't need to be there.  Thanks.


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Wednesday, January 21, 2015 1:40 PM
  • Graham,

    No joy.  End user reports Word crashes on:

    lngPidlFound = SHGetSpecialFolderLocation(0, lngFolder, lngPidl) 'Word crashes on this line.

    Do you have Windows 8.1/Office 2013 (64x)?  I didn't think you did and all that is left to do is wait until someone who does can test and confirm that this code works hence the problem is with the end user's arrangement or the code doesn't work.

    Felipe, did you test with Windows 8.1/Office 2013 (64x)?


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Wednesday, January 21, 2015 2:02 PM
  • No, I didn't, and unfortunately, I don't have this setup anymore.

    If you are really in a hurry, I recomend installing AutoCAD 64 bits or Word Perfect 64 bits and test the API calls on their VBEs.

    This is the only way I know to test both bitness in the same enviroment without using virtual machine.



    Felipe Costa Gualberto - http://www.ambienteoffice.com.br

    Wednesday, January 21, 2015 4:46 PM
  • Felipe,

    Ok.  No, I'm not it that big of a hurry and I can wait until if or when someone who has that setup will test and advise.  Thanks.


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Friday, January 23, 2015 1:54 PM