IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Qt Discussion :

Probléme de conversion vc++ -> Qt


Sujet :

Qt

  1. #1
    Membre éclairé
    Avatar de alpha_one_x86
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    411
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Somme (Picardie)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2006
    Messages : 411
    Par défaut Probléme de conversion vc++ -> Qt
    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?

  2. #2
    Membre expérimenté Avatar de MacPro
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    367
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Novembre 2007
    Messages : 367
    Par défaut
    De ce que j'en vois et ce que j'en comprends, c'est que le compilateur est venu lire tes fonctions et essaie de retrouver les prototypes correspondant par la signature (nombre, ordre, type des arguments) et qu'il n'y arrive pas.

    Il faut donc que tu te débrouilles pour connaître le prototype exact des fonctions, et les appeler en donnant exactement les bons paramètres du bon type (tu peux toujours caster lorsque cela est possible).

  3. #3
    Membre éclairé
    Avatar de alpha_one_x86
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    411
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Somme (Picardie)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2006
    Messages : 411
    Par défaut
    Voila le code que j'ai du réadapter le code d'injection de la dll pour qu'il passe sous mingw + gcc:
    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
    /***************************************************************************
    *   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>
     
    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","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;
    }
    La fonction est bien appeler, puis:
    SUCCEEDED(hResult) revoie false donc le 1er block est sauté. donc ça vas ligne 84:
    Ensuite SCODE_CODE(hResult) != ERROR_ACCESS_DENIED car en l'affichant par un QString::number() ça me fait SCODE_CODE(hResult)==262

  4. #4
    yan
    yan est déconnecté
    Rédacteur
    Avatar de yan
    Homme Profil pro
    Ingénieur expert
    Inscrit en
    Mars 2004
    Messages
    10 035
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur expert
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2004
    Messages : 10 035
    Par défaut
    Salut.
    Si je comprend le code, c'est juste pour executer regsvr32.exe avec des parametre.
    Alors pourquoi ne pas utiliser QProcess?????

  5. #5
    Membre éclairé
    Avatar de alpha_one_x86
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    411
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Somme (Picardie)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2006
    Messages : 411
    Par défaut
    1ere partie il essaye une autre méthode et seulement ensuite il fond ça, bonne idée, j'avais même pas compris que ça fessait ça.
    Et la sur du windows XP c'est sensée entrer dans la 1ere partie, je sais pas pk, ni si c'est spécifique à xp, ou si juste la 2eme partie est vraiment utile.

    En plus la 2eme partie n'est pas exécuter à cause de la clause, et je pense qu'il y a une raison.

  6. #6
    yan
    yan est déconnecté
    Rédacteur
    Avatar de yan
    Homme Profil pro
    Ingénieur expert
    Inscrit en
    Mars 2004
    Messages
    10 035
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur expert
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2004
    Messages : 10 035
    Par défaut
    Citation Envoyé par alpha_one_x86 Voir le message
    1ere partie il essaye une autre méthode et seulement ensuite il fond ça, bonne idée, j'avais même pas compris que ça fessait ça.
    Et la sur du windows XP c'est sensée entrer dans la 1ere partie, je sais pas pk, ni si c'est spécifique à xp, ou si juste la 2eme partie est vraiment utile.

    En plus la 2eme partie n'est pas exécuter à cause de la clause, et je pense qu'il y a une raison.
    La Première utilise une dll COM.
    Si la second marche, t'embête pas. Sinon, demande des précisions sur le forum C++.
    Ce ne sera plus un problème Qt

  7. #7
    Membre éclairé
    Avatar de alpha_one_x86
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    411
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Somme (Picardie)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2006
    Messages : 411
    Par défaut
    ok je vais poster la bas. Car c'est vrai que j'ai du mal à faire l'intéraction Qt <-> win32 mais la ça n'as plus rien à voir avec Qt.

Discussions similaires

  1. problème de conversion de dimension dans BUSINESS OBJECT
    Par greatmaster1971 dans le forum Deski
    Réponses: 4
    Dernier message: 28/04/2014, 13h15
  2. - [CAST ou CONVERT] Problème de conversion de date
    Par Boublou dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 06/07/2004, 14h31
  3. Problème de conversion 3DS->.X
    Par JBernn dans le forum DirectX
    Réponses: 5
    Dernier message: 08/04/2004, 19h08
  4. Problème de conversion unicode
    Par djmalo dans le forum C
    Réponses: 5
    Dernier message: 09/03/2004, 11h48
  5. Réponses: 11
    Dernier message: 02/09/2003, 14h20

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo