I have a program using API calls for the common dialog functions, but have run into a minor issue with one of my users who runs the program on Wine. (Linux)
Here's how I load up the structure that I send to the API:
Then I handle the return value as follows:Code:Private Function GetStructure(pstrPath As String, pstrFile As String, pstrFilter As String, pstrDefaultExt As String, penFlags As FlagsEnum) As OPENFILENAME Const OFN_FILEMUSTEXIST = &H1000 Const OFN_PATHMUSTEXIST = &H800 Const OFN_HIDEREADONLY = &H4 Const OFN_LONGNAMES = &H200000 Const OFN_OVERWRITEPROMPT = &H2 Const OF_WRITE = &H1 Const MAX_PATH = 260 With GetStructure .lStructSize = Len(GetStructure) .hwndOwner = Screen.ActiveForm.hwnd .hInstance = App.hInstance .lpstrFilter = Replace(pstrFilter, "|", Chr(0)) & Chr(0) .nMaxFile = MAX_PATH + 1 .nMaxFileTitle = MAX_PATH + 1 .lpstrFileTitle = Space(MAX_PATH) .lpstrInitialDir = pstrPath .lpstrDefExt = pstrDefaultExt Select Case penFlags Case feOpen .lpstrTitle = "Open" .lpstrFile = Space(MAX_PATH) .flags = OFN_FILEMUSTEXIST + OFN_HIDEREADONLY + OFN_LONGNAMES Case feSaveAs .lpstrTitle = "Save As" .lpstrFile = pstrFile & Space$(MAX_PATH - Len(pstrFile)) .flags = OFN_PATHMUSTEXIST + OFN_HIDEREADONLY + OFN_LONGNAMES + OF_WRITE ' + OFN_OVERWRITEPROMPT End Select End With End FunctionThis works great in Windows, but for the guy running Wine, he's getting the full 260 characters in his save dialog default filename. If he just clicks the Save button without doing anything, the program crashes with a stack dump termination.Code:ShowSaveAsDialog = Left$(typFileName.lpstrFile, InStr(typFileName.lpstrFile, Chr$(0)) - 1)
My question:
Can I change the MAX_PATH values in the structure part to be the length of the string, or will that cause problems in Windows if the user chooses a longer filename (or path) than what I'm putting there as a default?




Reply With Quote