Creating shortcut on 64-bit Vista

Hello,

I am creating a short-cut to an installed application in the "C:\Program Files (x86)" folder, but the target always seems to point to the "C:\Program Files" folder, the only problem with this is the short-cut icon shown is the default one. But if i double-click the short-cut, the app is invoked fine. If i invoke properties of the short-cut and then change the target to "C:\Program Files (x86)\Sample\test.exe" , the icon displayed is correct.

Is this a problem with the 64-bit Vista shell or am i doing something wrong in the below mentioned program. My appname istest.exeand is installed in the "C:\\Program Files (x86)\\Sample" folder.

All the folders usedin the below program were valid one's on my system.

This same program works fine on XP-64 bit.

Regards,

HRESULT CreateLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc, LPCSTR lpszWorkDir) ;

int _tmain(int argc, _TCHAR* argv[])

{

CoInitialize(NULL);

HRESULT ret = CreateLink("C:\\Program Files (x86)\\Sample\\test.exe","c:\\users\\public\\desktop\\test.lnk","Test","C:\\Program Files (x86)\\Sample");

if(SUCCEEDED(ret))

printf("\nCreate link succeeded");

else

printf("\nCreate link failed");

CoUninitialize();

return 0;

}

HRESULT CreateLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc, LPCSTR lpszWorkDir)

{

HRESULT hres;

IShellLink* psl;

// Get a pointer to the IShellLink interface.

hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,

IID_IShellLink, (LPVOID*)&psl);

if (SUCCEEDED(hres))

{

printf("\nSucceded in creating an instance");

IPersistFile* ppf;

// Set the path to the shortcut target and add the description.

psl->SetPath(lpszPathObj);

psl->SetDescription(lpszDesc);

psl->SetWorkingDirectory(lpszWorkDir);

//psl->SetIconLocation(lpszWorkDir, 0);

// Query IShellLink for the IPersistFile interface for saving the

// shortcut in persistent storage.

hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);

if (SUCCEEDED(hres))

{

WCHAR wsz[MAX_PATH];

printf("\nSucceded in querying interface");

// Ensure that the string is Unicode.

if(MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH))

{

// TODO: Check return value from MultiByteWideChar to ensure success.

printf("\nSucceded in conversion");

char pszGetPath[MAX_PATH];

if(SUCCEEDED(psl->GetPath(pszGetPath,MAX_PATH,NULL,SLGP_RAWPATH)))

printf("\nGet Path: %s",pszGetPath);

else

printf("\nGet Path failed");

// Save the link by calling IPersistFile::Save.

hres = ppf->Save(wsz, TRUE);

}

ppf->Release();

}

psl->Release();

}

return hres;

}

[4226 byte] By [PavanKR_ind] at [2007-12-23]

Software Development for Windows Vista

Site Classified