Creating Shortct, Create Link does not work 
Author Message
 Creating Shortct, Create Link does not work

[VC 4.0, Win 98]

Hi
      I wanted to create shortcut to a file through program and put on
desktop.
 Noting some of the replies for similar problem, I copied the MSDN function
CreateLink and pasted in my
program. It is a global function.

HRESULT CreateLink(LPCSTR lpszPathObj,
    LPSTR lpszPathLink, LPSTR lpszDesc)
{
    HRESULT hres;
    IShellLink* psl;

    // Get a pointer to the IShellLink interface.
    hres = CoCreateInstance(&CLSID_ShellLink, NULL,
        CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl);
    if (SUCCEEDED(hres)) {
        IPersistFile* ppf;

        // Set the path to the shortcut target, and add the
        // description.
        psl->lpVtbl->SetPath(psl, lpszPathObj);
        psl->lpVtbl->SetDescription(psl, lpszDesc);

       // Query IShellLink for the IPersistFile interface for saving the
       // shortcut in persistent storage.
        hres = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile,
            &ppf);

        if (SUCCEEDED(hres)) {
            WORD wsz[MAX_PATH];

            // Ensure that the string is ANSI.
            MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1,
                wsz, MAX_PATH);

            // Save the link by calling IPersistFile::Save.
            hres = ppf->lpVtbl->Save(ppf, wsz, TRUE);
            ppf->lpVtbl->Release(ppf);
        }
        psl->lpVtbl->Release(psl);
    }
    return hres;

Quote:
}

I get the error   C2065   IShellLink : undeclared identifier  (and all related variables have the same error)
I tried including some header files like <comdef..h>,<shlobj.h>, <shlobj.h>,<ole2.h>,<win32api.h>
<objbase.h>  but it does not work.  I am not familier with COM but I do not know any other method of
creating shortcut.

Kindly help

Thanks in advance

----milind  



Wed, 11 May 2005 15:14:36 GMT  
 Creating Shortct, Create Link does not work
I suspect that his won't be definitive, but I just put the VC4 CD into
drive D, opened a command prompt and set the PATH to the D:\MSDEV\BIN
directory and set the INCLUDE environment variable to the
D:\MSDEV\INCLUDE directory, copied your function verbatim to a file
named 'shortcut4.c' in the current directory and added the lines...

    #include <windows.h>
    #include <shlobj.h>

...to the top, and then ran the compiler from the command line using...

    CL /c shortcut4.c

...and it compiled without error. If it would help at all, I could email
you the 731 byte *.obj file.

--
Jeff Partch [VC++ MVP]


Quote:
> [VC 4.0, Win 98]

> Hi
>       I wanted to create shortcut to a file through program and put on
> desktop.
>  Noting some of the replies for similar problem, I copied the MSDN
function
> CreateLink and pasted in my
> program. It is a global function.

> HRESULT CreateLink(LPCSTR lpszPathObj,
>     LPSTR lpszPathLink, LPSTR lpszDesc)
> {
>     HRESULT hres;
>     IShellLink* psl;

>     // Get a pointer to the IShellLink interface.
>     hres = CoCreateInstance(&CLSID_ShellLink, NULL,
>         CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl);
>     if (SUCCEEDED(hres)) {
>         IPersistFile* ppf;

>         // Set the path to the shortcut target, and add the
>         // description.
>         psl->lpVtbl->SetPath(psl, lpszPathObj);
>         psl->lpVtbl->SetDescription(psl, lpszDesc);

>        // Query IShellLink for the IPersistFile interface for saving
the
>        // shortcut in persistent storage.
>         hres = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile,
>             &ppf);

>         if (SUCCEEDED(hres)) {
>             WORD wsz[MAX_PATH];

>             // Ensure that the string is ANSI.
>             MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1,
>                 wsz, MAX_PATH);

>             // Save the link by calling IPersistFile::Save.
>             hres = ppf->lpVtbl->Save(ppf, wsz, TRUE);
>             ppf->lpVtbl->Release(ppf);
>         }
>         psl->lpVtbl->Release(psl);
>     }
>     return hres;
> }

> I get the error   C2065   IShellLink : undeclared identifier  (and all

related variables have the same error)
Quote:
> I tried including some header files like <comdef..h>,<shlobj.h>,

<shlobj.h>,<ole2.h>,<win32api.h>
Quote:
> <objbase.h>  but it does not work.  I am not familier with COM but I

do not know any other method of

- Show quoted text -

Quote:
> creating shortcut.

> Kindly help

> Thanks in advance

> ----milind



Wed, 11 May 2005 16:28:10 GMT  
 Creating Shortct, Create Link does not work
Well, this worked on my machine too ! So atleast the code seems to be
correct.
so i added shortcut4.c to my project and removed the code from my original
project file.

I also realized that some settings like precompile header options does
affect.
After some trials on settings, the code compiles correctly in my
Environment.
I still get the error while linking the project ---(named setup) .

Linking...
shortcut4.obj : error LNK2001: unresolved external symbol _IID_IPersistFile
Debug/Setup.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Setup.exe - 2 error(s), 0 warning(s)

Any suggestions ?

thanks again


Quote:
> I suspect that his won't be definitive, but I just put the VC4 CD into
> drive D, opened a command prompt and set the PATH to the D:\MSDEV\BIN
> directory and set the INCLUDE environment variable to the
> D:\MSDEV\INCLUDE directory, copied your function verbatim to a file
> named 'shortcut4.c' in the current directory and added the lines...

>     #include <windows.h>
>     #include <shlobj.h>

> ...to the top, and then ran the compiler from the command line using...

>     CL /c shortcut4.c

> ...and it compiled without error. If it would help at all, I could email
> you the 731 byte *.obj file.

> --
> Jeff Partch [VC++ MVP]



> > [VC 4.0, Win 98]

> > Hi
> >       I wanted to create shortcut to a file through program and put on
> > desktop.
> >  Noting some of the replies for similar problem, I copied the MSDN
> function
> > CreateLink and pasted in my
> > program. It is a global function.

> > HRESULT CreateLink(LPCSTR lpszPathObj,
> >     LPSTR lpszPathLink, LPSTR lpszDesc)
> > {
> >     HRESULT hres;
> >     IShellLink* psl;

> >     // Get a pointer to the IShellLink interface.
> >     hres = CoCreateInstance(&CLSID_ShellLink, NULL,
> >         CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl);
> >     if (SUCCEEDED(hres)) {
> >         IPersistFile* ppf;

> >         // Set the path to the shortcut target, and add the
> >         // description.
> >         psl->lpVtbl->SetPath(psl, lpszPathObj);
> >         psl->lpVtbl->SetDescription(psl, lpszDesc);

> >        // Query IShellLink for the IPersistFile interface for saving
> the
> >        // shortcut in persistent storage.
> >         hres = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile,
> >             &ppf);

> >         if (SUCCEEDED(hres)) {
> >             WORD wsz[MAX_PATH];

> >             // Ensure that the string is ANSI.
> >             MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1,
> >                 wsz, MAX_PATH);

> >             // Save the link by calling IPersistFile::Save.
> >             hres = ppf->lpVtbl->Save(ppf, wsz, TRUE);
> >             ppf->lpVtbl->Release(ppf);
> >         }
> >         psl->lpVtbl->Release(psl);
> >     }
> >     return hres;
> > }

> > I get the error   C2065   IShellLink : undeclared identifier  (and all
> related variables have the same error)
> > I tried including some header files like <comdef..h>,<shlobj.h>,
> <shlobj.h>,<ole2.h>,<win32api.h>
> > <objbase.h>  but it does not work.  I am not familier with COM but I
> do not know any other method of
> > creating shortcut.

> > Kindly help

> > Thanks in advance

> > ----milind



Thu, 12 May 2005 06:36:23 GMT  
 Creating Shortct, Create Link does not work

Quote:
> After some trials on settings, the code compiles correctly in my
> Environment.
> I still get the error while linking the project ---(named setup) .

> Linking...
> shortcut4.obj : error LNK2001: unresolved external symbol
_IID_IPersistFile
> Debug/Setup.exe : fatal error LNK1120: 1 unresolved externals
> Error executing link.exe.
> Setup.exe - 2 error(s), 0 warning(s)

> Any suggestions ?

Try adding 'uuid.lib' to the linkers list of object/library modules.

--
Jeff Partch [VC++ MVP]



Thu, 12 May 2005 11:47:54 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Attributes not created when ConstructorInfo.Invoke used to create object

2. Create daemon Not working

3. async_uuid in ATL Created idl file does not work

4. SetWindowText() not working with buttons created in OnInitDialog.

5. Appwizard-created control does not work

6. Created control will not work under CE 3.0(x86 IPC)

7. Creating a Virtual directory through a program as done by VS.NET IDE

8. C++/ATL/ADO - Intellisense not working (statement completion options) not working

9. Links not working properly in the Object Browser

10. Help, linking not working.

11. Incrementally link not working!

12. ActiveX links in helpfiles do not work

 

 
Powered by phpBB® Forum Software