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

C++ Discussion :

Injecter dll dans windows, dragdropevent hanlder


Sujet :

C++

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  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 Injecter dll dans windows, dragdropevent hanlder
    Suite à ce topic:
    http://www.developpez.net/forums/d64...rsion-vcpp-qt/
    Dans ce 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
    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;
    }
    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.
    Par contre quand je fait ça:
    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!";
    	}
    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.

  2. #2
    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
    Tout ça:
    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
    	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!";
    	}
    Qui est apparemment utile pour que ça marche n'est pas exécuter.
    Quelqu'un peu me dire à quoi ça sert et aussi pourquoi la dll ne creer pas ces clef (dll ou systéme).

  3. #3
    Expert éminent
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 393
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

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

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 393
    Par défaut
    RegSvr32 ne fait qu'appeler une fonction exportée par la DLL.
    Si la DLL n'implémente pas correctement la fonction en question, ben...
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  4. #4
    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, pourquoi il y a 2 méthode implémenter et non pas qu'une?

  5. #5
    Expert éminent
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 393
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

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

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 393
    Par défaut
    Une pour enregistrer (DllRegisterServer), une autre pour désenregistrer (DllUnregisterServer). C'est tout ce que regsvr32 demande, le reste n'est que détails d'implémentation.
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  6. #6
    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
    Une petite aide pour convertir ça en c++ traditionnel serai la bienvenu comme ça je pourrai faire moi même ma propre dll, dans le dossier chext/:
    http://downloads.sourceforge.net/cop...0&big_mirror=0
    Par ce que le je lutte je comprend rien à l'API win32 (ou peu) et ça utilise des truc non standard qu'il faut convertir si non pas moyen de compiler la dll.

  7. #7
    Expert confirmé

    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2007
    Messages
    4 253
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2007
    Messages : 4 253
    Billets dans le blog
    3
    Par défaut
    Tu es conscient que tu parles d'une DLL d'extension du Shell (l'UI graphique) de Windows ?
    Vouloir "porter" cette DLL relève de la gageure à mon avis... mais bon...

    Pour que l'explorateur windows (l'UI du shell) puisse "découvrir" un certain nombre d'extension, il faut lui dire ce qu'il doit aller chercher.... Et c'est fait par le registre.
    Comme il n'y a pas d'executable à proprement parler, l'installation de ces fonctionalité se fait par enregistrement automatique (regsvr32).

    SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved
    Va dire "hey ! cette DLL, elle est pas vérolée, tu peux l'executer". Attention, l'écriture dans cette clé du registre nécessite des "elevated rights".

    Ensuite, c'est du détail à regarder dans la doc des shell extensions sur MSDN.

    Et que je redémarre, ça marche.
    Ca marche *aussi* sans redémarrer...la machine.... En fait, il faut redémarrer l'explorateur windows (pour qu'il charge la DLL), c'est tout. Attention en faisant des tests de debug, une fois chargée par l'explorateur... la DLL est ... read-only ! (donc non recompilable !)

  8. #8
    Expert éminent
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 393
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

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

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 393
    Par défaut
    C'est dans ce genre de circonstances que je conseille *vivement* d'activer la case à cocher "ouvrir les fenêtres des dossiers dans des processus différents", si ce n'est pas déjà fait.
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

Discussions similaires

  1. importer une dll c dans windows Phone7
    Par jalil1988 dans le forum Windows Phone
    Réponses: 3
    Dernier message: 10/05/2012, 10h51
  2. Copie des dll dans Program Files (x86) sous windows 7 64 bits
    Par dot-_-net dans le forum Général Java
    Réponses: 5
    Dernier message: 03/03/2011, 11h52
  3. comment installer une dll dans le GAC?(windows 7)
    Par olivier57b dans le forum Windows 7
    Réponses: 0
    Dernier message: 19/05/2010, 03h09
  4. Copie d'une dll dans Program Files sous Windows 7
    Par Jean-Marie64 dans le forum Installation, Déploiement et Sécurité
    Réponses: 1
    Dernier message: 12/05/2010, 15h14
  5. Réponses: 1
    Dernier message: 12/01/2007, 21h40

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