Article View: cn.bbs.comp.program
Article #415Re: vc����
From: ���
Date: Sat, 22 Aug 1998 00:00
Date: Sat, 22 Aug 1998 00:00
72 lines
3344 bytes
3344 bytes
�� �� Mola_Wang@bbs.ustc.edu.cn (ħħ֮��) �Ĵ������ᵽ: ��
: sigh install shield��Ȼˬ��
: ������ijЩԭ�� ���ò��Լ�����.lnk
: ����˵IShellLink,IPersistFile�ӿڿ���ʵ�֣�����֪��ô��.
: ���ܰ�����?
���Կ���vc����, �й�IShell�ӿڵIJ���.
����ij����˵��ժ��vc�İ���:
Creating a Shortcut to a File
The CreateLink function in the following example creates a shortcut. The
parameters include a pointer to the name of the file to link to, a pointer
to the name of the shortcut that you are creating, and a pointer to the
description of the link. The description consists of the string,
��Shortcut to filename,�� where filename is the name of the file to link to.
Because CreateLink calls the CoCreateInstance function, it is assumed that
the CoInitialize function has already been called. CreateLink uses the
IPersistFile interface to save the shortcut and the IShellLink interface to
store the filename and description.
// CreateLink - uses the shell's IShellLink and IPersistFile interfaces
// to create and store a shortcut to the specified object.
// Returns the result of calling the member functions of the interfaces.
// lpszPathObj - address of a buffer containing the path of the object
// lpszPathLink - address of a buffer containing the path where the
// shell link is to be stored
// lpszDesc - address of a buffer containing the description of the
// shell link
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;
}
--
[m[1;37m�� ��Դ:���������� bbs.cst.sh.cn��[FROM: 202.127.16.22][m
Technical Details
Message-ID:
<3QBkdG$sr3@bbs.cst.sh.cn>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: Chinese,GB X-Google-Thread: fc86e,ec3853d06f10799e X-Google-Attributes: gidfc86e,public From: nicebean.bbs@bbs.cst.sh.cn (���) Subject: Re: vc���� Date: 1998/08/22 Message-ID: <3QBkdG$sr3@bbs.cst.sh.cn> X-Deja-AN: 383666277 Organization: ��������վ X-Filename: Programming/M.903755104.A Newsgroups: cn.bbs.comp.program