Home > Back-end >  Service with ole com components failed to perform locking shortcuts to the taskbar
Service with ole com components failed to perform locking shortcuts to the taskbar

Time:10-03

Code:

Void __fastcall CrnPinAppToWin7Taskbar (String strPath, String strApp) {
CoInitialize (0);//initialize the com component

Char filename []="c: \ \ 313. TXT";//here to write to the file name
Ofstream fout (filename);

The Variant vShell=CreateOleObject (" Shell. Application ");//create the shell class object

The Variant vFolder=vShell. OleFunction (" NameSpace ", WideString (strPath));


The Variant vFolderItem=vFolder. OleFunction (" ParseName, "WideString (strApp));


The Variant vItemVerbs=vFolderItem. OleFunction (" Verbs ");


//get the Pin to Taskbar Verb string
HINSTANCE hInst=: : LoadLibrary (" Shell32. DLL ");

TCHAR szPinName [256]={
0
};

: : LoadString (hInst, 5386, szPinName, 256);//find shell32. DLL's 5386th string

: : FreeLibrary (hInst);

String str;
Int nCount=vItemVerbs. OlePropertyGet (" Count ");//a total of 29 string

for (int i=0; I & lt; NCount; I++) {

STR=vItemVerbs. OleFunction (" Item ", I). OlePropertyGet (" Name ");



If (SameText (STR, szPinName)) {//service to enter
//63 63 72 75 6 2 63 6 f e e d
Fout<" In the same ";//enter ok
Fout<" \ n ";

The Variant res=vItemVerbs. OleFunction (" Item ", I). OleFunction (" DoIt ");//call doit function failure, direct return

//String STR=SysErrorMessage (: : GetLastError ());//error code without output
//char * str1=new char [STR. The Length () + 1);
//StrPCopy (str1, STR);
//fout

Fout & lt; <"\ n";//implementation of services are not
Fout & lt; <"Ok".
Fout & lt; <"\ n";
}
}
CoUninitialize ();//remove com form
}
This method from the Internet to find the demon elder brother, services outside no problem, but the service internal fail, after debugging, find errors at the time of call doit function failure, estimated or direct return, because the back of the debugging information in service execution is not
Aunt taught, that plagued the younger brother for a few days.. After debugging, the previous steps are no problem, but it is
The Variant res=vItemVerbs. OleFunction (" Item ", I). OleFunction (" DoIt "); Aunt will call fails, please advise...
Permissions, I created a administrator permissions to run the program or not, the process of path in what seems to be no use path

CodePudding user response:

Done, is the issue of environment variables

CodePudding user response:

Congratulations, you can reference posted answers to others,
  • Related