View URL files

Source: Internet
Author: User

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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.