Solved

Urgent!  Can someone compile this short code VC6.0 (prints windows shortcut info)

Posted on 2004-10-19
6
218 Views
Last Modified: 2010-04-01
Hi.  I need a program that I can execute like this:

<prompt>GetTarget.exe "c:\example\path\somelink.lnk"

Output:
  The TARGET field and nothing else.

Ex:
<prompt>GetTarget.exe "C:\Documents and Settings\All Users\Start Menu\Programs\Startup\Microsoft Office.lnk"

Output:
"C:\Program Files\Microsoft Office\Office\OSA9.EXE" -b -l

I found this code on the web and it looks like this is what I need but I don't have a compile installed and need this functionality soon.
Can someone please compile it for me so I can pass one argument (full path) and have it output the target + args.  If the file is not found or there is no target output nothing.

http://www.codeguru.com/Cpp/COM-Tech/shell/article.php/c1337

Thanks!  This is not a normal practice for me but I need this ASAP and do not have access to VC6.0 at the moment.  I made this worth the max number of points I could.  Thanks again.
0
Comment
Question by:JonAqua
  • 2
6 Comments
 
LVL 12

Accepted Solution

by:
OnegaZhang earned 500 total points
ID: 12355225
sample in MSDN

HRESULT ResolveIt(HWND hwnd, LPCSTR lpszLinkFile, LPSTR lpszPath)
{
    HRESULT hres;
    IShellLink* psl;
    char szGotPath[MAX_PATH];
    char szDescription[MAX_PATH];
    WIN32_FIND_DATA wfd;
 
    *lpszPath = 0; // assume failure
 
    // Get a pointer to the IShellLink interface.
    hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
                            IID_IShellLink, (LPVOID*)&psl);
    if (SUCCEEDED(hres))
    {
        IPersistFile* ppf;
 
        // Get a pointer to the IPersistFile interface.
        hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
            
        if (SUCCEEDED(hres))
        {
            WCHAR wsz[MAX_PATH];
 
            // Ensure that the string is Unicode.
            MultiByteToWideChar(CP_ACP, 0, lpszLinkFile, -1, wsz, MAX_PATH);
 
            // TODO: Check return value from MultiByteWideChar to ensure
                     success.
 
            // Load the shortcut.
            hres = ppf->Load(wsz, STGM_READ);
           
            if (SUCCEEDED(hres))
            {
                // Resolve the link.
                hres = psl->Resolve(hwnd, 0);

                if (SUCCEEDED(hres))
                {
                    // Get the path to the link target.
                    hres = psl->GetPath(szGotPath,
                                        MAX_PATH,
                                        (WIN32_FIND_DATA*)&wfd,
                                        SLGP_SHORTPATH);

                    if (SUCCEEDED(hres))
                    {
                        // Get the description of the target.
                        hres = psl->GetDescription(szDescription, MAX_PATH);

                        if (SUCCEEDED(hres))
                        {
                            hres = StringCbCopy(lpszPath, sizeof(lpszPath),
                                                szGotPath);
                            if (SUCCEEDED(hres))
                            {
                                // Handle success
                            }
                            else
                                // application-defined function
                                HandleErr(hres);
                        }
                    }
                }
            }

            // Release the pointer to the IPersistFile interface.
            ppf->Release();
        }

        // Release the pointer to the IShellLink interface.
        psl->Release();
    }
    return hres;
}
0
 

Author Comment

by:JonAqua
ID: 12356752
Thanks, my problem is I need a compiled binary because I dont have access to Visual Studio at the moment.
0
 

Author Comment

by:JonAqua
ID: 12356764
Nevermind I got it thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now