|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Dec 2007
Città: brianza
Messaggi: 717
|
[C++]Eccezione causata da un parametro passato per il risultato
Sto scrivendo un programma, del quale sotto c'è una parte del codice:
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; } Codice:
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. http://msdn.microsoft.com/en-us/libr...(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
__________________
AMD Ryzen 9700X MSI RX 480 Gaming X 8G ASRock B850 Pro-A Windows 11 Pro RAM DDR5 16GBx2 TEAMGROUP T-Create Expert 6000 MHz CL30 SSD Crucial T500 4TB case Corsair Carbide 200R |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Mar 2009
Messaggi: 753
|
... scusa, tu così facendo non passi un puntatore nullo?
non devi passare un puntatore che punta ad una variabile nulla? prova a dichiarare così: Codice:
LPWSTR ppszName = NULL; Codice:
psiResult[0].GetDisplayName(sigdnName, &ppszName); |
![]() |
![]() |
![]() |
#3 |
Senior Member
Iscritto dal: Dec 2007
Città: brianza
Messaggi: 717
|
Il parametro deve essere un puntatore.
__________________
AMD Ryzen 9700X MSI RX 480 Gaming X 8G ASRock B850 Pro-A Windows 11 Pro RAM DDR5 16GBx2 TEAMGROUP T-Create Expert 6000 MHz CL30 SSD Crucial T500 4TB case Corsair Carbide 200R |
![]() |
![]() |
![]() |
#4 |
Senior Member
Iscritto dal: Apr 2010
Città: Frosinone
Messaggi: 416
|
|
![]() |
![]() |
![]() |
#5 |
Senior Member
Iscritto dal: Dec 2007
Città: brianza
Messaggi: 717
|
In effetti invece che creare un puntatore a LPWSTR e passarglielo direttamente alla funzione bastava creare una variabile LPWSTR e passare alla funzione l'indirizzo.
__________________
AMD Ryzen 9700X MSI RX 480 Gaming X 8G ASRock B850 Pro-A Windows 11 Pro RAM DDR5 16GBx2 TEAMGROUP T-Create Expert 6000 MHz CL30 SSD Crucial T500 4TB case Corsair Carbide 200R |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 19:35.