|
-
December 1st, 2008, 06:30 PM
#1
ShellExecuteEx()
hello,
i keep getting errors when i run the code from
http://www.codeguru.com/forum/showthread.php?t=302501
i added the appropiate header files, so my code is
Code:
#include <windows.h>
int main() {
SHELLEXECUTEINFO ExecuteInfo;
memset(&ExecuteInfo, 0, sizeof(ExecuteInfo));
ExecuteInfo.cbSize = sizeof(ExecuteInfo);
ExecuteInfo.fMask = 0;
ExecuteInfo.hwnd = 0;
ExecuteInfo.lpVerb = "open"; // Operation to perform
ExecuteInfo.lpFile = "c:\\windows\\notepad.exe"; // Application name
ExecuteInfo.lpParameters = "c:\\example.txt"; // Additional parameters
ExecuteInfo.lpDirectory = 0; // Default directory
ExecuteInfo.nShow = SW_SHOW;
ExecuteInfo.hInstApp = 0;
if(ShellExecuteEx(&ExecuteInfo) == FALSE)
// Could not start application -> call 'GetLastError()'
return 0;
}
the errors i get are:
1>------ Build started: Project: aaa, Configuration: Debug Win32 ------
1>Compiling...
1>aaa.cpp
1>c:\documents and settings\z\desktop\c++\aaa\aaa\aaa.cpp(12) : error C2440: '=' : cannot convert from 'const char [5]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\z\desktop\c++\aaa\aaa\aaa.cpp(13) : error C2440: '=' : cannot convert from 'const char [23]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\z\desktop\c++\aaa\aaa\aaa.cpp(14) : error C2440: '=' : cannot convert from 'const char [15]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>Build log was saved at "file://c:\Documents and Settings\z\Desktop\c++\aaa\aaa\Debug\BuildLog.htm"
1>aaa - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
what is wrong with my code?
and what do i have to do to fix it?
im also using windows XP
thanks for help in advance, zac
-
December 1st, 2008, 06:38 PM
#2
Re: ShellExecuteEx()
The problem is that you are using ANSI strings, but are compiling in UNICODE.
Include <tchar.h> and use the _T() macro.
For example
Code:
ExecuteInfo.lpFile = _T("c:\\windows\\notepad.exe");
Not related but you don't need to use memset anymore. Instead you can let the compiler initialize a structure.
Code:
SHELLEXECUTEINFO ExecuteInfo = { 0 };
-
December 1st, 2008, 06:45 PM
#3
Re: ShellExecuteEx()
[SOLVED]
thanks for the help =)
-
August 18th, 2010, 08:28 AM
#4
Re: ShellExecuteEx()
hi all,
I had a weired behavior in my application. In my application there is dialog box and on which there is a link and when i clicked on that a Google page gets opened with help of shellexecuteEx Function.But when my dialogue is on desktop and when i clicked on link then It does not open.But when my dialog gets closed then Google search page gets opened. Can anyone help me???i am trying it from last four days
-
August 18th, 2010, 11:41 AM
#5
Re: ShellExecuteEx()
 Originally Posted by varun.choudhary
hi all,
I had a weired behavior in my application. In my application there is dialog box and on which there is a link and when i clicked on that a Google page gets opened with help of shellexecuteEx Function.But when my dialogue is on desktop and when i clicked on link then It does not open.But when my dialog gets closed then Google search page gets opened. Can anyone help me???i am trying it from last four days
If might help us if you posted some relavent code using code tags.
-
September 15th, 2010, 03:17 AM
#6
Re: ShellExecuteEx()
SHELLEXECUTEINFO ShExecInfo;
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = L"open";
ShExecInfo.lpFile = m_bExplore ? L"explorer.exe" : L"c:\\Program Files\\Internet Explorer\\iexplore.exe";
ShExecInfo.lpParameters = m_cstrURL;
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOWNORMAL;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
if(ShExecInfo.hProcess)
CloseHandle(ShExecInfo.hProcess);
-
September 15th, 2010, 03:47 AM
#7
Re: ShellExecuteEx()
Sry for being late.
i am still getting the same problem.
help me..
SHELLEXECUTEINFO ShExecInfo;
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = L"open";
ShExecInfo.lpFile = m_bExplore ? L"explorer.exe" : L"c:\\Program Files\\Internet Explorer\\iexplore.exe";
ShExecInfo.lpParameters = m_cstrURL;
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOWNORMAL;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
if(ShExecInfo.hProcess)
CloseHandle(ShExecInfo.hProcess);
-
September 16th, 2010, 02:13 AM
#8
Re: ShellExecuteEx()
hi all,
I had a weired behavior in my application. when run any exe on desktop and dialog box of my application appears on which a hyperlink is there and when clicked on hyperlink google page gets opened .But problem is that google page does not get open till i do not close the dialog.and when i close the dialog google page gets opened easily.
And suppose if i create the shorcut of same exe on desktop.then google page gets opened easily without closing the dialog.
Please help me.
SHELLEXECUTEINFO ShExecInfo;
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = L"open";
ShExecInfo.lpFile = m_bExplore ? L"explorer.exe" : L"iexplore.exe";
ShExecInfo.lpParameters = m_cstrURL;
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOWNORMAL;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
if(ShExecInfo.hProcess)
CloseHandle(ShExecInfo.hProcess);
-
September 16th, 2010, 02:29 AM
#9
Re: ShellExecuteEx()
You better would open your own thread rather than adding to a solved question.
Also please post your code into code blocks so that we easier can read them.
If you compare your code with that of zaac you'll will see that you didn't initialize the SHELLEXECUTEINFO structure. As Arjay already explained it simply could be done by
Code:
SHELLEXECUTEINFO ShExecInfo = { 0 };
I don't know whether it solves your issue but surely you should try it cause starting form Visual Studio would invoke the debugger which causes all memory to be initialized while starting from desktop might not do it that way.
-
September 16th, 2010, 03:17 AM
#10
Re: ShellExecuteEx()
Thanks for help.
Actually i am new to code guru.I dont how to open a new thread thats why i am doing like this.
Please tell me how to open a new thread.
I had initialized structure to zero also but it does not work.
Code is like this.
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = L"open";
ShExecInfo.lpFile = L"iexplore.exe";
ShExecInfo.lpParameters = m_cstrURL;
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOWNORMAL;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
if(ShExecInfo.hProcess)
CloseHandle(ShExecInfo.hProcess);
-
September 16th, 2010, 10:17 AM
#11
Re: ShellExecuteEx()
 Originally Posted by varun.choudhary
Thanks for help.
Actually i am new to code guru.I dont how to open a new thread thats why i am doing like this.
Please tell me how to open a new thread.
I had initialized structure to zero also but it does not work.
Code is like this.
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = L"open";
ShExecInfo.lpFile = L"iexplore.exe";
ShExecInfo.lpParameters = m_cstrURL;
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOWNORMAL;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
if(ShExecInfo.hProcess)
CloseHandle(ShExecInfo.hProcess);
I am not sure what you mean by not working try to use GetLastError() if function get failed .Which will help you to understand the reason of your problem.
Thanks
-
September 16th, 2010, 01:03 PM
#12
Re: ShellExecuteEx()
 Originally Posted by varun.choudhary
Thanks for help.
Actually i am new to code guru.I dont how to open a new thread thats why i am doing like this.
Please tell me how to open a new thread.
Use all your powers & all your skills as a 'computer programmer' & try to figure it out. If you can't...well....good luck with programming is all I can say!
-
September 16th, 2010, 01:37 PM
#13
Re: ShellExecuteEx()
 Originally Posted by Martin O
Use all your powers & all your skills as a 'computer programmer' & try to figure it out. If you can't...well....good luck with programming is all I can say! 
Hint1: you can't do it from the thread page, but can from the forum page.
Hint2: see the 'New Thread' button.
-
September 17th, 2010, 01:48 AM
#14
Re: ShellExecuteEx()
 Originally Posted by humptydumpty
I am not sure what you mean by not working try to use GetLastError() if function get failed .Which will help you to understand the reason of your problem.
Thanks..
Hi..
I had tried GetLastError(),Shellexecuteex is executing sucessfully.
-
September 17th, 2010, 01:59 AM
#15
Re: ShellExecuteEx()
 Originally Posted by Arjay
Hint1: you can't do it from the thread page, but can from the forum page.
Hint2: see the 'New Thread' button.
Hi..
GM :-)
I go to forum page.But from there i am not getting the new thread button.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|