Bonjour, voila j'essaye d'adapter un code existant et j'ai ça, je souhaite utilisé que la windows.h:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
register.cpp: In function `HRESULT RegisterShellExtDll(QString, bool)':
register.cpp:46: error: no matching function for call to `QString::toWCharArray(const TCHAR*[(((unsigned int)((int)(&lpszPath)->QString::length())) + 1u)])'
c:/Qt/4.4.3/include/QtCore/../../src/corelib/tools/qstring.h:310: note: candidates are: int QString::toWCharArray(wchar_t*) const
register.cpp:47: error: cannot convert `const TCHAR**' to `const WCHAR*' for argument `1' to `HINSTANCE__* LoadLibraryW(const WCHAR*)'
register.cpp:80: error: no matching function for call to `QString::toWCharArray(const TCHAR*[(((unsigned int)((int)(&strParams)->QString::length())) + 1u)])'
c:/Qt/4.4.3/include/QtCore/../../src/corelib/tools/qstring.h:310: note: candidates are: int QString::toWCharArray(wchar_t*) const
register.cpp:81: error: cannot convert `const TCHAR*[(((unsigned int)((int)(&strParams)->QString::length())) + 1u)]' to `const WCHAR*' in assignment
Voila le code:
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
HRESULT RegisterShellExtDll(QString lpszPath, bool bRegister)
{
	// 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))
	{
		HRESULT (STDAPICALLTYPE *pfn)(void);
		LPCTSTR temp[lpszPath.length()+1];
		lpszPath.toWCharArray(temp);
		HINSTANCE hMod = LoadLibrary(temp);// load the dll
		if(hMod == NULL)
			hResult = HRESULT_FROM_WIN32(GetLastError());
		if(SUCCEEDED(hResult) && !hMod)
			hResult = E_FAIL;
		if(SUCCEEDED(hResult))
		{
			(FARPROC&)pfn = GetProcAddress(hMod, (bRegister ? "DllRegisterServer" : "DllUnregisterServer"));
			if(pfn == NULL)
				hResult = E_FAIL;
			if(SUCCEEDED(hResult))
				hResult = (*pfn)();
			CoFreeLibrary(hMod);
		}
		CoUninitialize();
	}
	// if previous operation failed (ie. vista system) - try running regsvr32 with elevated privileges
	if(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+"\"";
		LPCTSTR temp[strParams.length()+1];
		strParams.toWCharArray(temp);
		sei.lpParameters = temp;
		sei.nShow = SW_SHOW;
		if(!ShellExecuteEx(&sei))
			hResult = E_FAIL;
	}
	return hResult;
}
Quelqu'un peu me passer un petit coup de main?