The following code demonstrates how to create a URL file. The parameter meanings are as follows:
Pszurl: network address, such as the http://www.vchelp.net you can also make it point to a file such as: file: // local_file_name. Pszurlfilename: the URL file name, for example, C:/vchelp. url. Only vchelp is displayed when Windows is displayed, but not the extension. Szdescription: Description of the URL. Sziconfile: the icon file displaying the URL, which can be EXE or DLL. Index: Position of the icon in the file. Hresult createintershortcut (maid, maid, maid) {// create URL hresult hres through the shelllink interface; coinitialize (null ); optional * phook; hres = cocreateinstance (clsid_internetshortcut, null, clsctx_inproc_server, forward, (void **) & phook); // obtain the clsid_internetshortcut interface if (succeeded (hres )) {ipersistfile * PPF; ishelllink * PSL; // query ishelllink for the ipersistfile interface for hres = phook-> QueryInterface (iid_ipersistfile, (void **) & PPF ); hres = phook-> QueryInterface (iid_ishelllink, (void **) & PSL); If (succeeded (hres) {word wsz [max_path]; // buffer for Unicode string // set the path to the specified cut target. phook-> seturl (pszurl, 0); hres = PSL-> seticonlocation (sziconfile, nindex); If (succeeded (hres) {// set the description of the shortcut. hres = PSL-> setdescription (szdescription); If (succeeded (hres) {// ensure that the string consists of ANSI characters. multibytetowidechar (cp_acp, 0, pszurlfilename,-1, wsz, max_path); // Save the saved cut via the ipersistfile: Save member function. hres = PPF-> Save (wsz, true) ;}// release the pointer to ipersistfile. PPF-> release (); PSL-> release ();} // release the pointer to ishelllink. phook-> release ();} return hres ;}
Similarly, if the shelllink interface is used, the file information can be obtained through functions such as getarguments, getdescription, geticonlocation, and getpath.
If you open the URL file to view it, you will find that the file structure is similar to that of the INI file, such as the content of the Visual C ++ help. URL file,
[InternetShortcut]URL=http://www.vchelp.net/
Therefore, using the following method to create a URL file is also successful, and avoid using the interface
BOOL CreateMyUrlFile(const char * strURL,
const char * strURLFileName,
const char * strIconfile,
const int nIndex)
{
ofstream urlfile;
urlfile.open(strURLFileName, ios::out | ios::trunc );
if(urlfile.is_open())
{
urlfile <<endl<<"[InternetShortcut]"<<endl;
if(strIconfile)
{
urlfile<<"IconIndex="<<nIndex<<endl
<<"IconFile="<<strIconfile<<endl;
}
urlfile<<"URL="<<strURL<<endl;
urlfile.close();
return TRUE;
}
return FALSE;
}
In addition, you can call getprivateprofilestring/writeprivateprofilestring to read/write the URL file.