Thread View: borland.public.cppbuilder.nativeapi
3 messages
3 total messages
Started by Anthony
Thu, 05 Jul 2007 11:43
Shortcut Information
Author: Anthony
Date: Thu, 05 Jul 2007 11:43
Date: Thu, 05 Jul 2007 11:43
66 lines
3061 bytes
3061 bytes
I have a problem where if i obtain the icon location for the shortcut Adobe
reader 8.0 it causes an access violation. The icon location is:
C:\WINDOWS\Installer\{AC76BA86-7AD7-1033-7B44-A81000000003}\SC_Reader.exe
It seems to collect and save the icon location fine, but if i close the form
its running on i receive the AV and im not sure why. It also only seems to
happen to the Adobe reader shortcut, all other shortcut (icon locations)
seem to be fine.
From what i can tell it seems to be the length of the string not so much the
information, but how can i change it to accept any length?
Can anyone point me in the right direction for what im
doing wrong?
char * pszFile;
pszFile = location.c_str();
string LnkInfo = "";
HRESULT hres;
IShellLink* pShellLink = NULL;
//Initialise COM
CoInitialize(NULL);
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (LPVOID*)&pShellLink);
if (SUCCEEDED(hres))
{
IPersistFile* ppf;
// Get a pointer to the IPersistFile interface.
hres = pShellLink->QueryInterface(IID_IPersistFile, (void**)&ppf);
if (SUCCEEDED(hres))
{
WCHAR wsz[MAX_PATH];
// Ensure that the string is Unicode.
MultiByteToWideChar(CP_ACP, 0, pszFile, -1, wsz, MAX_PATH);
// Load the shortcut.
hres = ppf->Load(wsz, STGM_READ);
if (SUCCEEDED(hres))
{
HWND hwnd;
// Resolve the link.
hres = pShellLink->Resolve(hwnd, 0);
if (SUCCEEDED(hres))
{
int iShow;
unsigned short usHotKey;
_WIN32_FIND_DATAA pfd;
char buf[10];
//obtain shortcut information
pShellLink->GetPath(pszFile,MAX_PATH,
&pfd, SLGP_UNCPRIORITY);
ISSUE---------->>>> pShellLink->GetIconLocation(pszFile, MAX_PATH,
&iShow); <<<<----------PROBLEM LINE
//
etc....
Re: Shortcut Information
Author: Remy Lebeau (TeamB)
Date: Thu, 05 Jul 2007 17:48
Date: Thu, 05 Jul 2007 17:48
31 lines
1830 bytes
1830 bytes
"Anthony" <anfo@hotmail.com> wrote in message
news:468cd95d@newsgroups.borland.com...
> char * pszFile;
> pszFile = location.c_str();
<snip>
> pShellLink->GetPath(pszFile,MAX_PATH, &pfd, SLGP_UNCPRIORITY);
> pShellLink->GetIconLocation(pszFile, MAX_PATH, &iShow);
You are writing both output values to the same char*, which in turn is
pointing at the string object's internal buffer. If the string was
not preallocated to at least MAX_PATH characters, then you are going
to be writing into the surrounding memory.
I suggest you use a separate buffer, just like you are when calling
Load(), ie:
char buf[MAX_PATH+1] = {0};
if( SUCCEEDED(pShellLink->GetPath(buf, MAX_PATH, &pfd,
SLGP_UNCPRIORITY)) )
location = buf;
memset(buf, 0, sizeof(buf));
if( SUCCEEDED(pShellLink->GetIconLocation(buf, MAX_PATH,
&iShow)) )
location = buf;
Gambit
Re: Shortcut Information
Author: Anthony
Date: Sat, 07 Jul 2007 03:44
Date: Sat, 07 Jul 2007 03:44
1 lines
912 bytes
912 bytes
worked a treat thanks...
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads