ı am writing in microsoft visual c++ 6.0.... ı need get full file path from its shortcut... ı found in msdn but ı dont understand anything.. can explain this method or give simple example??
http://msdn.microsoft.com/en-us/libr...72(VS.85).aspx
ı am writing in microsoft visual c++ 6.0.... ı need get full file path from its shortcut... ı found in msdn but ı dont understand anything.. can explain this method or give simple example??
http://msdn.microsoft.com/en-us/libr...72(VS.85).aspx
Last edited by koyboy; 05-07-2008 at 08:28 AM. Reason: rewrite link
That Path has nothing to do with file system paths, but paths as in the edges of a polygon (for example).
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
yes first link isnt wroking ... ı think you dont understand me rags_to_riches.. ı use microsoft visual c++ 6.0 and these
#include <objidl.h> /* For IPersistFile */
#include <shlobj.h> /* For IShellLink */
includes not working on.. :S.. can you give another advice :S
So, perhaps an incorrectly installed PlatformSDK? Get a new one. And while you're at it, get Visual C++.Net 2008 Express. It's free, and it's not 12 years old.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
ı have visual studio 2008 full.. thanks for advice .. but if ı write program in vs 2008 its need framework... ı dont want it... ı have do without framework
Tested and works in VS 2008 (running on XP SP3 in a VMware Fusion VM under Mac OS X):
You need to create the right kind of project (Visual C++) that doesn't use the CLR.Code:#include <windows.h> #include <objidl.h> /* For IPersistFile */ #include <shlobj.h> /* For IShellLink */ #if defined(_MSC_VER) #pragma comment(lib, "ole32.lib") #pragma comment(lib, "uuid.lib") #endif /* * GetShortcutTarget * Retrieves the path that a shortcut file points to. * * Paramaters: * szShortcutFile The path to the shortcut file. * szTarget Pointer to a buffer that will receive the target path. * The buffer length should be at least MAX_PATH characters. * cchTarget The size of the szTarget buffer, in characters. * * Return: * A non-zero value is returned on success. If the function fails zero * will be returned. GetLastError can NOT be called to get an additional error code. * * Runtime requirements: * CoInitialize or CoInitializeEx must have been called before using this function. * * Compile requirements: * C. Include <windows.h>, <objidl.h> & <shlobj.h>. Link "uuid.lib". */ BOOL GetShortcutTarget(LPCTSTR szShortcutFile, LPTSTR szTarget, SIZE_T cchTarget) { IShellLink* psl = NULL; IPersistFile* ppf = NULL; BOOL bResult = FALSE; # if !defined(UNICODE) WCHAR wsz[MAX_PATH]; if (0 == MultiByteToWideChar(CP_ACP, 0, szShortcutFile, -1, wsz, MAX_PATH) ) goto cleanup; # else LPCWSTR wsz = szShortcutFile; # endif if (FAILED( CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **) &psl) )) goto cleanup; if (FAILED( psl->QueryInterface(IID_IPersistFile, (void **) &ppf) )) goto cleanup; if (FAILED( ppf->Load(wsz, STGM_READ) )) goto cleanup; if (NOERROR != psl->GetPath(szTarget, cchTarget, NULL, 0) ) goto cleanup; bResult = TRUE; cleanup: if (ppf) ppf->Release(); if (psl) psl->Release(); if (!bResult && cchTarget != 0) szTarget[0] = TEXT('\0'); return bResult; } #if 1 /* Test code. */ #include <stdio.h> #include <tchar.h> int main(void) { TCHAR szTarget[MAX_PATH]; CoInitialize(NULL); GetShortcutTarget( TEXT("C:\\Documents and Settings\\All Users\\Start Menu\\") TEXT("Programs\\Accessories\\Calculator.lnk"), szTarget, MAX_PATH); _tprintf(TEXT("The shortcut target is '%s'.\n"), szTarget); CoUninitialize(); getchar(); return 0; } #endif
thanks a lot man.. ı get header files from vs 2008 and include c++ 6.0... than thats ok it works but ı have one more questions.. if ı do this in vs 2008 it need framework.. it is true or false?? how can ı do this in vs 2008 and the exe not need the framework :S
False. Read the last sentence again:
The CLR is the Common Language Runtime. I created a Visual C++->Win32->Win32 Console Project.You need to create the right kind of project (Visual C++) that doesn't use the CLR.
ı copy my app.'s code to Visual C++->Win32->Win32 Console Project but ı have too many problemm.. ok thats not important.. ı cont. write in c++ 6.0.. thanks all of you for advice.. ı am sory my english
It is probably too late to give comment in this topics. But I couldnt resist (I even applied to be a member here) it. With only one reason to start with :
From many C/C++ programmers codes in the internet, most are avoiding goto statements (because it is against structural principle), as the result thier codes are more unreadable (too many nested if statment). They are forget that the main goal for structural languages are for readable. So goto statments are still usefull as long as we know how to do it properly (like in this example, go to End). Good Job
Of course there are better way still, Like the ATL but yes this is an ok use of goto.
Code:CComPtr<IShellLink> psl
Woop?
Uninteresting thread bump
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.