.lnk file format
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.... -donald murray ============================================ c version ============================================ #include <windows.h> #include <windowsx.h> #include <objbase.h> #include <shlobj.h> #include <stdio.h> #include <initguid.h> #include <string.h> main(int ac, char *av[]) { ishelllink *psl; hresult hres; win32_find_data wfd; char szgotpath[max_path]; ipersistfile *ppf; if (ac != 2) { printf("syntax: ln <pathname>\n"); return 0; } hres = coinitialize(null); if (!succeeded(hres)) printf("could not open the com library\n"); hres = cocreateinstance(&clsid_shelllink, null, clsctx_inproc_server, &iid_ishelllink, (lpvoid *)&psl); if (succeeded(hres)) { hres = psl->lpvtbl->queryinterface(psl, &iid_ipersistfile, &ppf); if (succeeded(hres)) { word wsz[max_path]; multibytetowidechar(cp_acp, 0, av[1], -1, wsz, max_path); hres = ppf->lpvtbl->load(ppf, wsz, stgm_read); if (succeeded(hres)) { hres = psl->lpvtbl->resolve(psl, 0, slr_any_match); if (succeeded(hres)) { strcpy(szgotpath, av[1]); hres = psl->lpvtbl->getpath(psl, szgotpath, max_path, (win32_find_data *)&wfd, slgp_shortpath ); if (!succeeded(hres)) printf("getpath failed!\n"); printf("this points to %s\n", wfd.cfilename); if (wfd.dwfileattributes & file_attribute_directory) printf("this is a directory\n"); } } else printf("ipersistfile load error\n"); ppf->lpvtbl->release(ppf); } else printf("queryinterface error\n"); psl->lpvtbl->release(psl); } else printf("cocreateinstance error - hres = %08x\n", hres); return 0; } ================================== c++ version ================================== #include <windowsx.h> #include <objbase.h> #include <shlobj.h> #include <stdio.h> #include <initguid.h> #include <stdlib.h> #include <io.h> #include <string.h> // this program should print out whether the file is a link and where it // points to and whether it is a directory or not. // main(int ac, char *av[]) { if (ac != 2) { printf("syntax: ln <pathname>\n"); return 0; } ishelllink *psl; // pointer to ishelllink i/f hresult hres; win32_find_data wfd; char szgotpath[max_path]; // get pointer to the ishelllink interface. hres = cocreateinstance(clsid_shelllink, null, clsctx_inproc_server, iid_ishelllink, (lpvoid *)&psl); if (succeeded(hres)) { // get pointer to the ipersistfile interface. ipersistfile *ppf; hres = psl->queryinterface(iid_ipersistfile, (lpvoid *)&ppf); if (succeeded(hres)) { word wsz[max_path]; // ensure string is unicode. multibytetowidechar(cp_acp, 0, av[1], -1, wsz, max_path); // load the shell link hres = ppf->load(wsz, stgm_read); if (succeeded(hres)) { // resolve the link. hres = psl->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. if (succeeded(hres)) { strcpy(szgotpath, av[1]); hres = psl->getpath(szgotpath, max_path, (win32_find_data *)&wfd, slgp_shortpath ); if (!succeeded(hres)) printf("getpath failed!\n"); printf("this points to %s\n", wfd.cfilename); if (wfd.dwfileattributes & file_attribute_directory) printf("this is a directory\n"); } } else printf("ipersistfile load error\n"); ppf->release(); } else printf("queryinterface error\n"); psl->release(); } else printf("cocreateinstance error - hres = %08x\n", hres); return 0; } |