winapi - program exits when shellexcute was called -
win7 os, vs2008. program disappears when shellexcute called,
it's wtl project , code these:
*.h
command_handler(idc_btn_login, bn_clicked, dologin)
*.cpp
lresult xloginview::dologin(word, word, hwnd, bool&) { ::shellexecute(null, _t("open"), _t("http://mysite.com/login.php"), null,null, sw_show); return 0; }
when login button clicked, program disappeard , visual studio exit too.
even code such simple these:
int _tmain(int argc, tchar* argv[], tchar* envp[]) { int nretcode = 0; // initialize mfc , print , error on failure if (!afxwininit(::getmodulehandle(null), null, ::getcommandline(), 0)) { // todo: change error code suit needs _tprintf(_t("fatal error: mfc initialization failed\n")); nretcode = 1; } else { // todo: code application's behavior here. shellexecute(null, l"open", l"http://stackoverflow.com", null, null, sw_show); } return nretcode; }
the site (http://stackoverflow.com) openned first running or debugging, second time , over, visual studio disappears @ same time.
here same problem, didn't give reason http://bbs.pediy.com/showthread.php?t=130968
update 2013-08-27
as iinspectable's suggestion, works ok local resource, web resource.
google chrome default browser, trust other browsers default browser, these result below:
(1) default browser: google chrome
if directly run program, ok, works. web resource(url) openned, program doesn't crush.
but if debug program visual studio's button "start debugging", not program exit visual studio exit when button who's event code calls "shellexcute".
(2) default browser: firfox or internet explorer
the program works, doesn't crush or disappear whenever run directly or debug visual studio.
as above think maybe it's because program's privilege not enough. trust code below, problem disappeared.
void upprivilege() { handle htoken; token_privileges tkp; openprocesstoken (getcurrentprocess (), token_adjust_privileges | token_query, &htoken); lookupprivilegevalue(null, l"sedebugprivileges", &tkp.privileges[0].luid); tkp.privilegecount = 1; tkp.privileges[0].attributes = se_privilege_enabled; adjusttokenprivileges(htoken, false, &tkp, 0, null, 0); }
update 2013-08-27
as iinspectable's suggestion, works ok local resource, web resource.
google chrome default browser, trust other browsers default browser, these result below:
(1) default browser: google chrome
if directly run program, ok, works. web resource(url) openned, program doesn't crush.
but if debug program visual studio's button "start debugging", not program exit visual studio exit when button who's event code calls "shellexcute".
(2) default browser: firfox or internet explorer
the program works, doesn't crush or disappear whenever run directly or debug visual studio.
as above think maybe it's because program's privilege not enough. trust code below, problem disappeared.
void upprivilege() { handle htoken; token_privileges tkp; openprocesstoken (getcurrentprocess (), token_adjust_privileges | token_query, &htoken); lookupprivilegevalue(null, l"sedebugprivileges", &tkp.privileges[0].luid); tkp.privilegecount = 1; tkp.privileges[0].attributes = se_privilege_enabled; adjusttokenprivileges(htoken, false, &tkp, 0, null, 0); }
Comments
Post a Comment