| 3041 | // from FCreateProgramGroup() and FCreateDesktopIcon() to setup program. |
| 3042 | |
| 3043 | flag FCreateShortcut(CONST char *szDir, CONST char *szName, |
| 3044 | CONST char *szFile, CONST char *szDesc, int nIcon) |
| 3045 | { |
| 3046 | IShellLinkA *pisl = NULL; |
| 3047 | IPersistFile *pipf = NULL; |
| 3048 | char sz[cchSzMax], *pch; |
| 3049 | WCHAR wsz[cchSzMax]; |
| 3050 | HRESULT hr; |
| 3051 | flag fRet = fFalse; |
| 3052 | |
| 3053 | // Define the link data. |
| 3054 | hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, |
| 3055 | IID_IShellLink, (LPVOID *)&pisl); |
| 3056 | if (FAILED(hr)) |
| 3057 | goto LExit; |
| 3058 | GetModuleFileName(wi.hinst, sz, cchSzMax); |
| 3059 | if (nIcon >= 0) { |
| 3060 | hr = pisl->SetIconLocation(sz, nIcon); |
| 3061 | if (FAILED(hr)) |
| 3062 | goto LExit; |
| 3063 | } |
| 3064 | for (pch = sz; *pch; pch++) |
| 3065 | ; |
| 3066 | while (pch > sz && *pch != '\\') |
| 3067 | pch--; |
| 3068 | *pch = chNull; |
| 3069 | hr = pisl->SetWorkingDirectory(sz); |
| 3070 | if (FAILED(hr)) |
| 3071 | goto LExit; |
| 3072 | sprintf(pch, "\\%s", szFile); |
| 3073 | hr = pisl->SetPath(sz); |
| 3074 | if (FAILED(hr)) |
| 3075 | goto LExit; |
| 3076 | if (szDesc == NULL) |
| 3077 | szDesc = szName; |
| 3078 | hr = pisl->SetDescription(szDesc); |
| 3079 | if (FAILED(hr)) |
| 3080 | goto LExit; |
| 3081 | |
| 3082 | // Save it to a link file. |
| 3083 | hr = pisl->QueryInterface(IID_IPersistFile, (LPVOID *)&pipf); |
| 3084 | if (FAILED(hr)) |
| 3085 | goto LExit; |
| 3086 | sprintf(sz, "%s", szDir); |
| 3087 | for (pch = sz; *pch; pch++) |
| 3088 | ; |
| 3089 | sprintf(pch, "\\%s.lnk", szName); |
| 3090 | MultiByteToWideChar(CP_ACP, 0, sz, -1, wsz, cchSzMax); |
| 3091 | hr = pipf->Save(wsz, fTrue); |
| 3092 | if (FAILED(hr)) |
| 3093 | goto LExit; |
| 3094 | |
| 3095 | fRet = fTrue; |
| 3096 | LExit: |
| 3097 | if(pipf) |
| 3098 | pipf->Release(); |
| 3099 | if(pisl) |
| 3100 | pisl->Release(); |
no outgoing calls
no test coverage detected