Thanks.
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
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.
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.
>
>
>
>
>
Thanks,
-- Bryan
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
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.