I need a help how to create shortcut in c++ by using the IShellLink method .
I try to make one like this http://www.intelliproject.net/articl...ortcut_cpp_com
but It gives many errors using Dev C++ compiler.
I dont know what files shall I include.
4: error: `CString' was not declared in this scope
4: error: `CString' was not declared in this scope
5: error: initializer expression list treated as compound expression
5: error: expected `,' or `;' before '{' token
In function `int main()':
41: error: `CreateShortCut' cannot be used as a function
4: error: `CString' was not declared in this scope
4: error: `CString' was not declared in this scope
5: error: initializer expression list treated as compound expression
5: error: expected `,' or `;' before '{' token
In function `int main()':
41: error: `CreateShortCut' cannot be used as a function
Execution terminated
Well, as I can see the problem is CString only (all further ones are caused by that), and it has nothing to do with shell link. You have to provide an implementation of CString class, or otherwise go with some other string implementation.
Igor ....Thanks it working good now but by Visual studio .
using Dev c++ required
#include <comdef.h> // for _bstr_t
which required some more headers file .
....any suggestion how can I use someting else than _bstr_t to make it work on Dev
( I need Dev becuse my whole app compiled by Dev)
In fact, the point is to provide OLESTR string (which is just a WCHAR string). So this would do:
Code:
WCHAR wshortcut[MAX_PATH] = {0};
mbstowcs(wshortcut, shortCut, MAX_PATH); // you need this only if your original string is MBCS one
hr = pIPF->Save(wshortcut,FALSE);
IShellLink::SetPath() seems to jerk with the slashes and quotes that are passed in. I need to have something like
c:\windows\system32\cmd.exe /C "C:\Program Files\Microsoft Is Killing Me\ForReal.bat"
in the shortcut target. This exact string above works if I use the GUI and type it into the Target field on the shortcut properties. However, SetPath() adds a leading and trailing quotation mark and changes the forward slash to a backslash.
Is there a way to use the IShellLink interface and specify *exactly* what is used for the target string?
Please read my original post more carefully. My problem is not with the escaping of the quotes or backslash.
My problem is
#1 - IShellLink::SetPath() changes a *forward slash* to a backslash. This is the "/C" following the "cmd.exe" in my string. You don't need to escape forward slashes in C++ strings
#2 - Having the quotes put at the beginning and end of my string makes the shortcut not work. What I want to be the target is
The foward slash to backslash issue is not as big of a deal as the quote issue. If I want to call out cmd.exe followed by a path with spaces in it, it's not possible with IShellLink::SetPath().
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.