Hi everyone.
How to get folder as const string? I tried every way but I can't.
Error: Constant expression is required.
How to get folder as const string? I tried every way but I can't.
Code:
Private Declare Function SHGetSpecialFolderPath Lib "shell32.dll" Alias "SHGetSpecialFolderPathA" ( _
ByVal hwndOwner As Long, _
ByVal lpszPath As String, _
ByVal nFolder As Long, _
ByVal fCreate As Long) As Long
Private Const CSIDL_APPDATA As Long = &H1A
Public Enum FolderConstants
AppData = CSIDL_APPDATA
End Enum
Public Function GetSpecialFolder(folder As FolderConstants)
Dim tmp$
tmp$ = Space(260)
SHGetSpecialFolderPath(0&, tmp$, folder, 0)
GetSpecialFolder = Trim(tmp$)
End Function
Code:
Dim UserAppData = GetSpecialFolder(FolderConstants.AppData) & "\GetMyDll.dll"
Code:
Const ConstStr = UserAppData & vbCr
<DllImport(ConstStr)>
Private Shared Function GetMyFunc(ByVal GetValue As String) As String 'C++ .dll
End Function