Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Creating a Shortcut file using C

22 views
Skip to first unread message

Cédric MARTIGNAT

unread,
Jan 5, 1999, 3:00:00 AM1/5/99
to
I would like my application to create a shortcut (to itself) in the startup
group. Does anyone know the structure of a shortcut (.LNK) file ?


Thanks.

Cédric MARTIGNAT

unread,
Jan 5, 1999, 3:00:00 AM1/5/99
to

Cédric MARTIGNAT

unread,
Jan 5, 1999, 3:00:00 AM1/5/99
to

Cédric MARTIGNAT

unread,
Jan 5, 1999, 3:00:00 AM1/5/99
to

Cédric MARTIGNAT

unread,
Jan 5, 1999, 3:00:00 AM1/5/99
to

John A. Grant

unread,
Jan 5, 1999, 3:00:00 AM1/5/99
to
Cédric MARTIGNAT wrote in message <76tbcn$1...@s1.cetelyon.asi.fr>...

>I would like my application to create a shortcut (to itself) in the startup
>group. Does anyone know the structure of a shortcut (.LNK) file ?


Don't try to hack the .LNK file format - there's no guarantee
that it will not change in future versions.

The official way to add items to the Start menu is to use a
DDE(ML) conversation with "progman". See the "Shell
Dynamic Data Exchange Interface Overview" topic in
your .HLP files.

I suppose you could always use
SHGetSpecialFolderLocation(...CSIDL_STARTUP..)
and IShellLink()

--
John A. Grant * I speak only for myself * (remove 'z' to reply)
Airborne Geophysics, Geological Survey of Canada, Ottawa
If you followup, please do NOT e-mail me a copy: I will read it here

Jerry Coffin

unread,
Jan 6, 1999, 3:00:00 AM1/6/99
to
In article <76tbcn$1...@s1.cetelyon.asi.fr>,
cedric.m...@cetelyon.equipement.gouv.fr says...

> I would like my application to create a shortcut (to itself) in the startup
> group. Does anyone know the structure of a shortcut (.LNK) file ?

You don't need to know the format of the file -- in fact, you're
better off acting like you don't know anything about it, even though
it's pretty easy to figure out from looking at the file.

Instead, use IShellLink to create your shell links.


gdd

unread,
Jan 7, 1999, 3:00:00 AM1/7/99
to
You can use this code to create a shortcut:
I didn't write this myself and II don't know who wrote this originally
but it works

To find the place of a special folder and put in in a buffer (buf)

LPITEMIDLIST pidl;
SHGetSpecialFolderLocation(NULL,CSIDL_PROGRAMS,&pidl);
SHGetPathFromIDList(pidl,buf);

To create the link

__x_CreateLink( "PROGRAM.EXE", NULL, 0, NULL, 0,
SW_SHOWMINIMIZED, "C:\\Program Workdir", "Display Name",
buf );

The __x_Createlink source:


#define INC_OLE2
#include <windows.h>
#include <ole2.h>
#include <shlobj.h>
#include <objidl.h>
#include <stdio.h>

#pragma comment(lib,"uuid.lib")
#pragma comment(lib,"ole32.lib")
#pragma comment(lib,"shell32.lib")

HRESULT __x_CreateLink (
LPCSTR CommandLine,
LPCSTR Arguments,
WORD HotKey,
LPCSTR IconLocation,
int IconIndex,
int Show,
LPCSTR WorkingDirectory,
LPCSTR Description,
LPSTR LinkName
);


HRESULT __x_CreateLink (
LPCSTR CommandLine,
LPCSTR Arguments,
WORD HotKey,
LPCSTR IconLocation,
int IconIndex,
int Show,
LPCSTR WorkingDirectory,
LPCSTR Description,
LPSTR LinkName )
{
HRESULT hres;
IShellLink *psl;

if( (CommandLine==NULL) || (LinkName==NULL))
{
return ERROR_INVALID_PARAMETER;
}

hres = CoInitialize(NULL);
if( !SUCCEEDED(hres))
{
printf("CoInitialize failed, rc(%x),%x\n",hres,GetLastError());
return hres;
}

hres = CoCreateInstance( &CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl );

if( SUCCEEDED(hres))
{
IPersistFile *ppf;

psl->lpVtbl->SetPath( psl, CommandLine );

if( Description != NULL )
{
psl->lpVtbl->SetDescription( psl, Description );
}

if( Arguments != NULL )
{
psl->lpVtbl->SetArguments( psl, Arguments );
}

if( HotKey != 0 )
{
psl->lpVtbl->SetHotkey( psl, HotKey );
}

if( IconLocation != NULL )
{
psl->lpVtbl->SetIconLocation( psl, IconLocation,
IconIndex );
}

if( Show != -1 )
{
psl->lpVtbl->SetShowCmd( psl, Show );
}

if( WorkingDirectory != NULL )
{
psl->lpVtbl->SetWorkingDirectory( psl, WorkingDirectory );
}

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

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

MultiByteToWideChar( CP_ACP, 0, LinkName, -1,
wsz, MAX_PATH );

hres = ppf->lpVtbl->Save( ppf, wsz, TRUE );
ppf->lpVtbl->Release(ppf);
}
else
{
printf( "QueryInterface failed, rc(%x),%x\n", hres,
GetLastError());
}

psl->lpVtbl->Release(psl);
}
else
{
printf( "CoCreateInstance failed, rc(%x),%x\n", hres,
GetLastError());
}

CoUninitialize();
return hres;
}


Cédric MARTIGNAT <cedric.m...@cetelyon.equipement.gouv.fr> wrote in
article <76tbcn$1...@s1.cetelyon.asi.fr>...


> I would like my application to create a shortcut (to itself) in the
startup
> group. Does anyone know the structure of a shortcut (.LNK) file ?
>
>

> Thanks.
>
>
>
>
>

Bryan Loofbourrow

unread,
Jan 10, 1999, 3:00:00 AM1/10/99
to
Question: Suppose I'm making a shareware program that has the
capability to install a shortcut to itself in the startup menu. Do I
infer correctly that I have to include the redistributables for DCOM
in my installation process, to ensure that it will run on the original
Win95 (which, as I understand it did not include DCOM)?

Thanks,

-- Bryan


Chris Marriott

unread,
Jan 10, 1999, 3:00:00 AM1/10/99
to

Bryan Loofbourrow wrote in message <36992163....@news.serv.net>...


Shortcuts have nothing to do with DCOM; they use the "IShellLink" interface
which is a standard part of Windows 95.

Chris
-----------------------------------------------------------------------
Chris Marriott, SkyMap Software, UK (ch...@skymap.com)
Visit our web site at http://www.skymap.com
Astronomy software written by astronomers, for astronomers

John A. Grant

unread,
Jan 12, 1999, 3:00:00 AM1/12/99
to
Chris Marriott wrote in message
<916037457.15760.0...@news.demon.co.uk>...

>
>Bryan Loofbourrow wrote in message <36992163....@news.serv.net>...
>>Question: Suppose I'm making a shareware program that has the
>>capability to install a shortcut to itself in the startup menu. Do I
>>infer correctly that I have to include the redistributables for DCOM
>>in my installation process, to ensure that it will run on the original
>>Win95 (which, as I understand it did not include DCOM)?
>
>Shortcuts have nothing to do with DCOM; they use the "IShellLink" interface
>which is a standard part of Windows 95.


Speaking of which... I appreciate that IShellLink()
is used for creating shortcuts anywhere you want, but
what about Start Menu items?

The traditional formal approach to creating icons in program
groups for Windows 3.x, is to use a DDE(ML) conversation
with "progman". That approach also works for Windows
95/98/NT.

But in Win32, there is also the alternate approach of finding
the Start Menu | Programs folder with
ShGetSpecialFolderLocation(...,CSIDL_PROGRAMS,...)
and then using IShellLink() to create the shortcuts there.

So what is the recommended method for Start Menu |
Programs shortcuts? Is it still DDE with "progman"?

Chris Marriott

unread,
Jan 12, 1999, 3:00:00 AM1/12/99
to

John A. Grant wrote in message <77em4k$hg...@nrn2.NRCan.gc.ca>...

> Speaking of which... I appreciate that IShellLink()
> is used for creating shortcuts anywhere you want, but
> what about Start Menu items?
>
> The traditional formal approach to creating icons in program
> groups for Windows 3.x, is to use a DDE(ML) conversation
> with "progman". That approach also works for Windows
> 95/98/NT.
>
> But in Win32, there is also the alternate approach of finding
> the Start Menu | Programs folder with
> ShGetSpecialFolderLocation(...,CSIDL_PROGRAMS,...)
> and then using IShellLink() to create the shortcuts there.
>
> So what is the recommended method for Start Menu |
> Programs shortcuts? Is it still DDE with "progman"?


A "Start Menu" item is just a "lnk" file in the "Start Menu" directory. You
create it with IShellLink in just the same way you'd create a desktop
shortcut.

The old method of using DDE with ProgMan still works, but IShellLink is a
lot more flexible. If you're using a modern installation tool such as
"Wise", it's very easy to create lnks.

0 new messages