Suite à ce topic:
http://www.developpez.net/forums/d64...rsion-vcpp-qt/
Dans ce code:
L'exécution du programme "regsvr32.exe" me fait un beau message en plein dans l'écran. En plus de ça, cela ne marche pas.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119 /*************************************************************************** * Copyright (C) 2001-2008 by Józef Starosczyk * * ixen@copyhandler.com * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License * * (version 2) as published by the Free Software Foundation; * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ /*************************************************************************** register.cpp ------------------- Begin : Mon Nov 10 2008 13:20 alpha_one_x86 Project : Ultracopier Email : alpha.super-one@laposte.net Note : See README for copyright and developer Target : For interact with windows and the dll ****************************************************************************/ #include "register.h" #include "objbase.h" #include "env.h" #include <QString.h> #include <QProcess> HRESULT RegisterShellExtDll(QString lpszPath, bool bRegister) { DEBUGCONSOLE(70,"RegisterShellExtDll","start"); // first try - load dll and register it manually. HRESULT hResult = S_OK; // if failed - try by loading extension manually (would fail on vista when running as user) hResult = CoInitializeEx(NULL, COINIT_MULTITHREADED); if(SUCCEEDED(hResult)) { DEBUGCONSOLE(70,"RegisterShellExtDll","CoInitializeEx: ok"); HRESULT (STDAPICALLTYPE *pfn)(void); WCHAR temp[lpszPath.length()+1]; lpszPath.toWCharArray(temp); HINSTANCE hMod = LoadLibrary((WCHAR*)temp);// load the dll if(hMod == NULL) { hResult = HRESULT_FROM_WIN32(GetLastError()); DEBUGCONSOLE(70,"RegisterShellExtDll","hMod: NULL"); } if(SUCCEEDED(hResult) && !hMod) { DEBUGCONSOLE(70,"RegisterShellExtDll","SUCCEEDED(hResult): true && hMod: false"); hResult = E_FAIL; } if(SUCCEEDED(hResult)) { DEBUGCONSOLE(70,"RegisterShellExtDll","SUCCEEDED(hResult): true"); (FARPROC&)pfn = GetProcAddress(hMod, (bRegister ? "DllRegisterServer" : "DllUnregisterServer")); if(pfn == NULL) { DEBUGCONSOLE(70,"RegisterShellExtDll","pfn: NULL"); hResult = E_FAIL; } if(SUCCEEDED(hResult)) { DEBUGCONSOLE(70,"RegisterShellExtDll","SUCCEEDED(hResult): true"); hResult = (*pfn)(); } CoFreeLibrary(hMod); } CoUninitialize(); } else { DEBUGCONSOLE(70,"RegisterShellExtDll","SUCCEEDED(hResult): false"); } // if previous operation failed (ie. vista system) - try running regsvr32 with elevated privileges if(SCODE_CODE(hResult) == ERROR_ACCESS_DENIED) { DEBUGCONSOLE(70,"RegisterShellExtDll","SCODE_CODE(hResult): ERROR_ACCESS_DENIED"); hResult = S_FALSE; // try with regsvr32 SHELLEXECUTEINFO sei; memset(&sei, 0, sizeof(sei)); sei.cbSize = sizeof(sei); sei.fMask = SEE_MASK_UNICODE; sei.lpVerb = TEXT("runas"); sei.lpFile = TEXT("regsvr32.exe"); QString strParams; if(bRegister) strParams = " \""+lpszPath+"\""; else strParams = " /u \""+lpszPath+"\""; WCHAR temp[strParams.length()*2+1]; strParams.toWCharArray((WCHAR*)temp); sei.lpParameters = temp; strParams.fromStdWString(temp); DEBUGCONSOLE(70,"RegisterShellExtDll","strParams: "+strParams); sei.nShow = SW_SHOW; if(!ShellExecuteEx(&sei)) { DEBUGCONSOLE(70,"RegisterShellExtDll","ShellExecuteEx(&sei): false"); hResult = E_FAIL; } } else { DEBUGCONSOLE(70,"RegisterShellExtDll","SCODE_CODE(hResult): "+QString::number(SCODE_CODE(hResult))); } return hResult; }
Par contre quand je fait ça:
Et que je redémarre, ça marche. C'est aussi pour ça que je cherche à injecter directement la dll, pour ne pas avoir à redémarrer.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 QString thePathInject=QCoreApplication::applicationDirPath()+"/inject32.dll"; WCHAR temp[thePathInject.length()+1]; int l=thePathInject.toWCharArray(temp)*2+1; if(!newRegQuery(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Classes\\CLSID\\{A7005AF0-D6E8-48AF-8DFA-023B1CF660A7}\\InProcServer32",NULL,temp,l)) { DEBUGCONSOLE(10,"setSystemCopyCatched","Could not write the Classes\\CLSID registry key!"); return "Could not write the Classes\\CLSID registry key!"; } if(!newRegQuery(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Classes\\CLSID\\{A7005AF0-D6E8-48AF-8DFA-023B1CF660A7}\\InProcServer32", L"ThreadingModel",L"Apartment", 20)) { DEBUGCONSOLE(10,"setSystemCopyCatched","Could not write the ThreadingModel registry key!"); return "Could not write the ThreadingModel registry key!"; } if(!newRegQuery(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Classes\\*\\shellex\\DragDropHandlers\\inject32",NULL,L"{A7005AF0-D6E8-48AF-8DFA-023B1CF660A7}", 80)) { DEBUGCONSOLE(10,"setSystemCopyCatched","Could not write the Classes\\* registry key!"); return "Could not write the Classes\\* registry key!"; } if(!newRegQuery(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Classes\\Directory\\shellex\\DragDropHandlers\\inject32", NULL, L"{A7005AF0-D6E8-48AF-8DFA-023B1CF660A7}", 80)) { DEBUGCONSOLE(10,"setSystemCopyCatched","Could not write the Classes\\Directory registry key!"); return "Could not write the Classes\\Directory registry key!"; } if(!newRegQuery(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Classes\\Drive\\shellex\\DragDropHandlers\\inject32", NULL, L"{A7005AF0-D6E8-48AF-8DFA-023B1CF660A7}", 80)) { DEBUGCONSOLE(10,"setSystemCopyCatched","Could not write the Classes\\Drive registry key!"); return "Could not write the Classes\\Drive registry key!"; } if(!newRegQuery(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Classes\\Folder\\shellex\\DragDropHandlers\\inject32", NULL, L"{A7005AF0-D6E8-48AF-8DFA-023B1CF660A7}", 80)) { DEBUGCONSOLE(10,"setSystemCopyCatched","Could not write the Classes\\Folder registry key!"); return "Could not write the Classes\\Folder registry key!"; } if(!newRegQuery(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved", L"{A7005AF0-D6E8-48AF-8DFA-023B1CF660A7}", L"inject32", 20)) { DEBUGCONSOLE(10,"setSystemCopyCatched","Could not write the Shell Extensions\\Approved registry key!"); return "Could not write the Shell Extensions\\Approved registry key!"; }
Partager