Re: Bug in SHBrowseForFolder API in Visual Basic - Urgent
- From: "Abdhul Saleem" <AbdhulSaleem@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 25 Aug 2005 11:51:31 -0700
Code snippets are given below.
-----------------------------------------
'API Declaration
Private Declare Function SHBrowseForFolder Lib "shell32" _
(lpbi As BrowseInfo) As Long
' Triggered while clicking the Browse button for CCS Message text box in
Local Dir tab
Private Sub cmdCCSBrowse_Click()
On Error GoTo ErrorHandler
'Assigns the path selected in the browse folder dialog box to the CCS
text box
txtLocalCCS.Text = gFBrowseFolder(frmPCSCLConfiguration.hwnd, "Export
Directory - ", "CCS Files", txtLocalCCS.Text)
Exit Sub
ErrorHandler:
'Track the log activity
Call gPTraceActivity(Err.Number, gConstShowStopper, Me.Name,
"cmdCCSBrowse_Click", Err.Description)
MsgBox gConstErrorMessage
End Sub
-------------------------------------------------------
Public Function gFBrowseFolder(llngFormWinHandle As Long, lstrTitle As
String, lstrSubTitle As String, lstrPreviousLocation) As String
On Error GoTo ErrorHandler
Dim lpIDList As Long
Dim sBuffer As String
Dim szTitle As String
Dim tBrowseInfo As BrowseInfo
' Title of Browse window
szTitle = lstrTitle
' Fields in browse window
With tBrowseInfo
.hWndOwner = llngFormWinHandle
.lpszTitle = lstrcat(szTitle, lstrSubTitle)
.ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
End With
lpIDList = SHBrowseForFolder(tBrowseInfo)
' Selection of folder in Browse window
If (lpIDList) Then
sBuffer = Space(MAX_PATH)
SHGetPathFromIDList lpIDList, sBuffer
sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
gFBrowseFolder = sBuffer
CoTaskMemFree lpIDList
Else
gFBrowseFolder = lstrPreviousLocation
End If
Exit Function
ErrorHandler:
'Change the mouse pointer
Screen.MousePointer = 0
'Update into log file
Call gPTraceActivity(Err.Number, gintLogLevel, fConstModuleName,
"gFBrowseFolder")
MsgBox gConstErrorMessage
End Function
--------------------------------------------------------
The crash happens upon invoking the browse button which inturn is used to
invoke the windows folder dialog to retreive a folder.
Is there a memory profiling tool which can be run to check on memory usage
in VB?
"MikeD" wrote:
>
> "Abdhul Saleem" <AbdhulSaleem@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:F7CB0D17-6F28-485C-8B87-4CC45FDB1CC4@xxxxxxxxxxxxxxxx
> > The following code gives an run time crash error.
> > If (lpIDList) Then
> > sBuffer = Space(MAX_PATH)
> > SHGetPathFromIDList lpIDList, sBuffer
> > sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
> > gFBrowseFolder = sBuffer
> > CoTaskMemFree lpIDList
> > Else
> > gFBrowseFolder = lstrPreviousLocation
> > End If
> >
> > The error returned in the event viewer is as follows
> > Faulting application pcsclv20.exe, version 1.0.0.0, faulting module
> > ntdll.dll, version 5.1.2600.2180, fault address 0x00011ec3.
>
>
> I'm guessing that pcsclv20.exe is the filename of your app? Aside from
> that, you should post the declarations for the API functions and constants
> you're using. It's possible those are declared incorrectly. It would also
> help if you could pinpoint exactly which line causes the crash. Presumably,
> it's the call to SHGetPathFromIDList, but we can't be sure of that.
> Finally, where and how is lpIDList declared (for that matter, sBuffer too)?
> You should always include declarations along with any code snippet.
>
> --
> Mike
> Microsoft MVP Visual Basic
>
>
>
.
- References:
- Bug in SHBrowseForFolder API in Visual Basic - Urgent
- From: Abdhul Saleem
- Re: Bug in SHBrowseForFolder API in Visual Basic - Urgent
- From: MikeD
- Bug in SHBrowseForFolder API in Visual Basic - Urgent
- Prev by Date: Re: Bug in SHBrowseForFolder API in Visual Basic - Urgent
- Next by Date: Re: Subtraction Bug in VB
- Previous by thread: Re: Bug in SHBrowseForFolder API in Visual Basic - Urgent
- Next by thread: Re: source code easily viewed?
- Index(es):