⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lnk.htm

📁 各种文件格式说明及程序描述
💻 HTM
字号:
<html>

<head>
<title>file:///e:/kaifa/format/windows/lnk.txt</title>
</head>

<body background="../jpg/di1.JPG">

<p align="center"><font size="6" color="#0000ff">.lnk file format</font></p>
<div align="center"><center>

<table border="0" width="88%">
<tr>
<td width="100%"><pre>it's been a while since i've messed with that, but i dug up the following
source code. it has been so long that i can't remember if this was the file
i got working, so someone should test it out (i don't have time). however,
it basically decodes the windows .lnk file format to find out what it is a
shortcut to, and determines if that is a directory (i was going to write a
unix type ln command using .lnk file formats.....). there are 2 files here.
one is a c version, the other is a c++ version.... hope this helps....</pre>
<pre>                                -donald murray</pre>
<pre>============================================
c version
============================================</pre>
<pre>#include &lt;windows.h&gt;
#include &lt;windowsx.h&gt;
#include &lt;objbase.h&gt;
#include &lt;shlobj.h&gt;
#include &lt;stdio.h&gt;
#include &lt;initguid.h&gt;
#include &lt;string.h&gt;</pre>
<pre>main(int ac, char *av[])
{
ishelllink *psl;
hresult hres;
win32_find_data wfd;
char szgotpath[max_path];
ipersistfile *ppf;</pre>
<pre>    if (ac != 2)
{
printf(&quot;syntax: ln &lt;pathname&gt;\n&quot;);
return 0;
}</pre>
<pre>    hres = coinitialize(null);
if (!succeeded(hres))
printf(&quot;could not open the com library\n&quot;);</pre>
<pre>    hres = cocreateinstance(&amp;clsid_shelllink, null, clsctx_inproc_server,
&amp;iid_ishelllink, (lpvoid *)&amp;psl);
if (succeeded(hres))
{
hres = psl-&gt;lpvtbl-&gt;queryinterface(psl, &amp;iid_ipersistfile, &amp;ppf);</pre>
<pre>        if (succeeded(hres))
{
word wsz[max_path];</pre>
<pre>            multibytetowidechar(cp_acp, 0, av[1], -1, wsz, max_path);</pre>
<pre>            hres = ppf-&gt;lpvtbl-&gt;load(ppf, wsz, stgm_read);
if (succeeded(hres))
{
hres = psl-&gt;lpvtbl-&gt;resolve(psl, 0, slr_any_match);</pre>
<pre>                if (succeeded(hres))
{
strcpy(szgotpath, av[1]);</pre>
<pre>                   hres = psl-&gt;lpvtbl-&gt;getpath(psl, szgotpath, max_path,
(win32_find_data *)&amp;wfd, slgp_shortpath );
if (!succeeded(hres))
printf(&quot;getpath failed!\n&quot;);</pre>
<pre>                   printf(&quot;this points to %s\n&quot;, wfd.cfilename);
if (wfd.dwfileattributes &amp; file_attribute_directory)
printf(&quot;this is a directory\n&quot;);
}
}
else
printf(&quot;ipersistfile load error\n&quot;);
ppf-&gt;lpvtbl-&gt;release(ppf);
}
else
printf(&quot;queryinterface error\n&quot;);
psl-&gt;lpvtbl-&gt;release(psl);
}
else
printf(&quot;cocreateinstance error - hres = %08x\n&quot;, hres);
return 0;
}
</pre>
<pre>==================================
c++ version
==================================</pre>
<pre>#include &lt;windowsx.h&gt;
#include &lt;objbase.h&gt;
#include &lt;shlobj.h&gt;
#include &lt;stdio.h&gt;
#include &lt;initguid.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;io.h&gt;
#include &lt;string.h&gt;
</pre>
<pre>// this program should print out whether the file is a link and where it
// points to and whether it is a directory or not.
//</pre>
<pre>main(int ac, char *av[])
{
if (ac != 2)
{
printf(&quot;syntax: ln &lt;pathname&gt;\n&quot;);
return 0;
}</pre>
<pre>    ishelllink *psl;                            // pointer to ishelllink i/f
hresult hres;
win32_find_data wfd;
char szgotpath[max_path];</pre>
<pre>    // get pointer to the ishelllink interface.</pre>
<pre>    hres = cocreateinstance(clsid_shelllink, null, clsctx_inproc_server,
iid_ishelllink, (lpvoid *)&amp;psl);</pre>
<pre>    if (succeeded(hres))
{
// get pointer to the ipersistfile interface.</pre>
<pre>        ipersistfile *ppf;
hres = psl-&gt;queryinterface(iid_ipersistfile, (lpvoid *)&amp;ppf);</pre>
<pre>        if (succeeded(hres))
{
word wsz[max_path];</pre>
<pre>            // ensure string is unicode.
multibytetowidechar(cp_acp, 0, av[1], -1, wsz, max_path);</pre>
<pre>            // load the shell link
hres = ppf-&gt;load(wsz, stgm_read);
if (succeeded(hres))
{
// resolve the link.</pre>
<pre>                hres = psl-&gt;resolve(0, slr_any_match);
//                  ^
// using 0 instead -| of hwnd, as hwnd is only used if
// interface needs to prompt for more information. should use
// hwnd from current console in the long run.</pre>
<pre>                if (succeeded(hres))
{
strcpy(szgotpath, av[1]);</pre>
<pre>                    hres = psl-&gt;getpath(szgotpath, max_path,
(win32_find_data *)&amp;wfd, slgp_shortpath );
if (!succeeded(hres))
printf(&quot;getpath failed!\n&quot;);</pre>
<pre>                    printf(&quot;this points to %s\n&quot;, wfd.cfilename);
if (wfd.dwfileattributes &amp; file_attribute_directory)
printf(&quot;this is a directory\n&quot;);
}
}
else
printf(&quot;ipersistfile load error\n&quot;);
ppf-&gt;release();
}
else
printf(&quot;queryinterface error\n&quot;);
psl-&gt;release();
}
else
printf(&quot;cocreateinstance error - hres = %08x\n&quot;, hres);
return 0;
}


</pre>
</td>
</tr>
</table>
</center></div>
<p align="center"><a href="../index.htm">返回</a></p>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -