To do something similar in VC++
Code:
#include <windows.h>//Essential stuff
#include <objbase.h>//get COM up and running
#include <Shlobj.h>//for interfaces
#include <comdef.h>
inline void TESTIT(HRESULT hRes){
if(FAILED(hRes))
throw _com_error(hRes);
}
struct COM_INIT{//setup com
COM_INIT(){CoInitialize(0);}
~COM_INIT(){CoUninitialize();}
}COM_INIT_;
int WINAPI WinMain(HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int Show){
char *lpstrTargetPath = "C:\\WINDOWS\\system32\\calc.exe";
WCHAR *lpwstrLinkPath = L"C:\\Documents and Settings\\All Users\\Desktop\\CalcLink.lnk";
try{
IShellLink* ISL = 0;
IPersistFile* IPF = 0;
TESTIT(CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *) &ISL));
TESTIT(ISL->SetPath(lpstrTargetPath));
TESTIT(ISL->QueryInterface(IID_IPersistFile,(void**)&IPF));
TESTIT(IPF->Save(lpwstrLinkPath, TRUE));
ISL->Release();
IPF->Release();
MessageBox(0,"Success!","",MB_OK);
}
catch(_com_error& e){
MessageBox(0,e.Description().length() ? e.Description() : "COM Error","",MB_OK);
}
return 0;
}