grigor91
07-05-2010, 21:28
Sto scrivendo un programma, del quale sotto c'è una parte del codice:
LPWSTR * openDialog(HWND hwnd)
{
IFileDialog *pfd;
IShellItem * psiResult = NULL;
LPWSTR *ppszName = NULL;
SIGDN sigdnName = SIGDN_NORMALDISPLAY;
// CoCreate the dialog object.
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd));
if (SUCCEEDED(hr))
{
// Show the dialog
hr = pfd->Show(hwnd);
if (SUCCEEDED(hr))
{
// Obtain the result of the user's interaction with the dialog.
IShellItem *psiResult = NULL;
hr = pfd->GetResult(&psiResult);
if (SUCCEEDED(hr))
{
psiResult[0].GetDisplayName(sigdnName, ppszName);
// Do something with the result.
psiResult->Release();
}
}
pfd->Release();
}
return ppszName;
}
Però quando eseguo dà questa eccezione:
First-chance exception at 0x759d7b64 in DirectShowProva.exe: 0xC0000005: Access violation writing location 0x00000000.
Unhandled exception at 0x759d7b64 in DirectShowProva.exe: 0xC0000005: Access violation writing location 0x00000000.
A me sembra che gli dia fastidio ppszName inizializzato a NULL, però anche da quello scritto qua:
http://msdn.microsoft.com/en-us/library/bb761140(v=VS.85).aspx
Io capisco che quella sia una variabile in cui la funzione metta il risultato, quindi non capisco come dovrei inizializzarla. Qualcuno ha dei suggerimenti?
P.S.: Uso Visual Studio 2010
LPWSTR * openDialog(HWND hwnd)
{
IFileDialog *pfd;
IShellItem * psiResult = NULL;
LPWSTR *ppszName = NULL;
SIGDN sigdnName = SIGDN_NORMALDISPLAY;
// CoCreate the dialog object.
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd));
if (SUCCEEDED(hr))
{
// Show the dialog
hr = pfd->Show(hwnd);
if (SUCCEEDED(hr))
{
// Obtain the result of the user's interaction with the dialog.
IShellItem *psiResult = NULL;
hr = pfd->GetResult(&psiResult);
if (SUCCEEDED(hr))
{
psiResult[0].GetDisplayName(sigdnName, ppszName);
// Do something with the result.
psiResult->Release();
}
}
pfd->Release();
}
return ppszName;
}
Però quando eseguo dà questa eccezione:
First-chance exception at 0x759d7b64 in DirectShowProva.exe: 0xC0000005: Access violation writing location 0x00000000.
Unhandled exception at 0x759d7b64 in DirectShowProva.exe: 0xC0000005: Access violation writing location 0x00000000.
A me sembra che gli dia fastidio ppszName inizializzato a NULL, però anche da quello scritto qua:
http://msdn.microsoft.com/en-us/library/bb761140(v=VS.85).aspx
Io capisco che quella sia una variabile in cui la funzione metta il risultato, quindi non capisco come dovrei inizializzarla. Qualcuno ha dei suggerimenti?
P.S.: Uso Visual Studio 2010