Board index » cppbuilder » AccessVialoation on SHGetSpecialFolderLocation
George Francis
CBuilder Developer |
George Francis
CBuilder Developer |
AccessVialoation on SHGetSpecialFolderLocation2005-08-06 05:22:10 AM cppbuilder10 Hello, I am trying to use the following code to read the user's Send To directory: char cBuf[MAX_PATH]; LPITEMIDLIST pidl; SHGetSpecialFolderLocation(0, CSIDL_SENDTO, &pidl); SHGetPathFromIDList(pidl, cBuf); It compiles OK, but I get an access violation Exception on the call to SHGetSpecialFolderLocation. Can anyone suggest why? |
Jonathan Benedicto
CBuilder Developer |
2005-08-06 05:34:53 AM
Re:AccessVialoation on SHGetSpecialFolderLocation
"George Francis" < XXXX@XXXXX.COM >wrote in message
QuoteHello, I am trying to use the following code to read the user's Send To { char Path[MAX_PATH + 1] = { 0 }; if( ::SHGetSpecialFolderPath( NULL, Path, Folder, 0 ) ) return AnsiString( Path ); return ""; } GetSpecialPath( CSIDL_SENDTO ); Jonathan |
George Francis
CBuilder Developer |
2005-08-06 05:57:56 AM
Re:AccessVialoation on SHGetSpecialFolderLocation
Jonathan Benedicto wrote:
Quote"George Francis" < XXXX@XXXXX.COM >wrote in message IUnknown* Unknown = CreateComObject(CLSID_ShellLink); IShellLink* ISLink = ((IShellLink*) Unknown ); ISLink->SetPath( _argv[0].c_str()); {smallsort} |
Jonathan Benedicto
CBuilder Developer |
2005-08-06 06:20:44 AM
Re:AccessVialoation on SHGetSpecialFolderLocation
"George Francis" < XXXX@XXXXX.COM >wrote in message
QuoteThanks but I've discovered the actual exception is being thrown from the Jonathan |
George Francis
CBuilder Developer |
2005-08-06 06:23:34 AM
Re:AccessVialoation on SHGetSpecialFolderLocation
Jonathan Benedicto wrote:
Quote"George Francis" < XXXX@XXXXX.COM >wrote in message |
Remy Lebeau (TeamB)
CBuilder Developer |
2005-08-06 07:54:55 AM
Re:AccessVialoation on SHGetSpecialFolderLocation
"George Francis" < XXXX@XXXXX.COM >wrote in message
QuoteSHGetSpecialFolderLocation(0, CSIDL_SENDTO, &pidl); LPITEMIDLIST pidl = NULL; if( SUCCEEDED(SHGetSpecialFolderLocation(0, CSIDL_SENDTO, &pidl)) ) { char cBuf[MAX_PATH+1] = {0}; SHGetPathFromIDList(pidl, cBuf); //... CoTaskMemFree(pidl); } Gambit |
Remy Lebeau (TeamB)
CBuilder Developer |
2005-08-06 07:56:04 AM
Re:AccessVialoation on SHGetSpecialFolderLocation
"George Francis" < XXXX@XXXXX.COM >wrote in message
QuoteIShellLink* ISLink = ((IShellLink*) Unknown ); counting) as well: IUnknown* Unknown = CreateComObject(CLSID_ShellLink); if( Unknown ) { IShellLink* ISLink = NULL; if( SUCCEEDED(Unknown->QueryInterface(IID_IShellLink, (void**)&ISLink)) ) { ISLink->SetPath( _argv[0].c_str()); //... ISLink->Release(); } Unknown->Release(); } Which can be wrapped using the DelphiInterface class (which CreateComObject() uses anyway): typedef DelphiInterface<IShellLink>_di_IShellLink; _di_IUnknown Unknown = CreateComObject(CLSID_ShellLink); if( Unknown ) { _di_IShellLink ISLink = Unknown; if( ISLink ) { ISLink->SetPath( _argv[0].c_str()); //... // do not call Release() here, DelphiInterface handles that automatically } // do not call Release() here, DelphiInterface handles that automatically } Which can be simplified to the following: typedef DelphiInterface<IShellLink>_di_IShellLink; _di_IShellLink ISLink = CreateComObject(CLSID_ShellLink); if( ISLink ) { ISLink->SetPath( _argv[0].c_str()); //... // do not call Release() here, DelphiInterface handles that automatically } Gambit |
Remy Lebeau (TeamB)
CBuilder Developer |
2005-08-06 07:57:36 AM
Re:AccessVialoation on SHGetSpecialFolderLocation
"George Francis" < XXXX@XXXXX.COM >wrote in message
QuoteISLink->SetPath( _argv[0].c_str()); ISLink->SetPath( _argv[0] ); Gambit |