comdlg32.dll中GetOpenFileName和GetSaveFileName在64bit环境中不能运行的解决
在64bitAccess中,原来32bit的Declare Function GetOpenFileName Lib "comdlg32.dll" 报错问题,可以通过下面方法解决:
第一步:在Delcare后面增加PtrSafe关键字。比如:
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
改为
Private Declare PtrSafe Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
第二步:改Long类型为LongPtr
将OPENFILENAME的hwndOwner、hInstance、lpfnHook三个类型由long改为LongPtr
第三步:将lStructSize中的Len()改为LenB()
如:Len(fFileName)改为LenB(fFileName)
这样就解决了32bit系统可以运行,而64bit中无法运行的问题。