P
Paul W
Hi everybody,
This may seem like a Shell question, but I believe it belongs here.
I'm trying to make a wrapper class for the SHBrowseForFolder function. This
function provides for a callback to your code for certain situations. I've
done this in c# but can't seem to get it to work here.
This is the delegate:
public __delegate int BrowseCallbackProc(HWND hWnd, UINT uMsg, LPARAM
lParam, LPARAM lpData);
This is the callback function (incomplete):
int FolderBrowserCallBack(HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM
lpData)
{
return 0;
} //FolderBrowserCallBack
And here's the function that sets it up (somewhat incomplete):
DialogResult ShowDialog(Form* Owner)
{
DialogResult retVal = DialogResult::Cancel;
BROWSEINFO bi;
BrowseCallbackProc* pBrowseCallbackProc = new BrowseCallbackProc(this,
&FolderBrowser::FolderBrowserCallBack);
ZeroMemory(&bi, sizeof(BROWSEINFO));
bi.hwndOwner = (HWND)Owner->Handle.ToPointer();
bi.ulFlags = (UINT)m_flags;
bi.pidlRoot = (LPITEMIDLIST)m_root;
bi.pszDisplayName = (LPWSTR)Marshal::StringToCoTaskMemUni(new String('\0',
MAX_PATH)).ToPointer();
bi.lpszTitle = (LPWSTR)Marshal::StringToCoTaskMemUni(m_title).ToPointer();
bi.lpfn = (BFFCALLBACK)pBrowseCallbackProc; // This assignment doesn't
seem to work
m_selectedPidl = SHBrowseForFolder(&bi); //
NullReferenceException occurs here
if (m_selectedPidl)
{
retVal = DialogResult::OK;
} //if (m_selectedPidl)
return retVal;
} //ShowDialog
When I run the code I get a NullReferenceException when calling
SHBrowseForFolder. When I step through, I find that even though
pBrowseCallbackProc appears to hold a valid address, bi.lpfn still shows
<undefined> after stepping through the assignment. This doesn't seem likely
to really be true because if you intentionally set this member to NULL, the
function works fine, albeit without the callback feature.
Thanks in advance for any help you can give me with this.
Paul
This may seem like a Shell question, but I believe it belongs here.
I'm trying to make a wrapper class for the SHBrowseForFolder function. This
function provides for a callback to your code for certain situations. I've
done this in c# but can't seem to get it to work here.
This is the delegate:
public __delegate int BrowseCallbackProc(HWND hWnd, UINT uMsg, LPARAM
lParam, LPARAM lpData);
This is the callback function (incomplete):
int FolderBrowserCallBack(HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM
lpData)
{
return 0;
} //FolderBrowserCallBack
And here's the function that sets it up (somewhat incomplete):
DialogResult ShowDialog(Form* Owner)
{
DialogResult retVal = DialogResult::Cancel;
BROWSEINFO bi;
BrowseCallbackProc* pBrowseCallbackProc = new BrowseCallbackProc(this,
&FolderBrowser::FolderBrowserCallBack);
ZeroMemory(&bi, sizeof(BROWSEINFO));
bi.hwndOwner = (HWND)Owner->Handle.ToPointer();
bi.ulFlags = (UINT)m_flags;
bi.pidlRoot = (LPITEMIDLIST)m_root;
bi.pszDisplayName = (LPWSTR)Marshal::StringToCoTaskMemUni(new String('\0',
MAX_PATH)).ToPointer();
bi.lpszTitle = (LPWSTR)Marshal::StringToCoTaskMemUni(m_title).ToPointer();
bi.lpfn = (BFFCALLBACK)pBrowseCallbackProc; // This assignment doesn't
seem to work
m_selectedPidl = SHBrowseForFolder(&bi); //
NullReferenceException occurs here
if (m_selectedPidl)
{
retVal = DialogResult::OK;
} //if (m_selectedPidl)
return retVal;
} //ShowDialog
When I run the code I get a NullReferenceException when calling
SHBrowseForFolder. When I step through, I find that even though
pBrowseCallbackProc appears to hold a valid address, bi.lpfn still shows
<undefined> after stepping through the assignment. This doesn't seem likely
to really be true because if you intentionally set this member to NULL, the
function works fine, albeit without the callback feature.
Thanks in advance for any help you can give me with this.
Paul