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

MFC Discussion :

Utilisation de dll


Sujet :

MFC

  1. #1
    Futur Membre du Club
    Inscrit en
    Janvier 2004
    Messages
    15
    Détails du profil
    Informations forums :
    Inscription : Janvier 2004
    Messages : 15
    Points : 9
    Points
    9
    Par défaut Utilisation de dll
    Dans un code j'utilise Kernel32.dll de W2k et psapi.dll de Wnt pour lister mes processus et leur id.
    mon exé fonctionne sur le 2 systèmes.

    Par contre certaines fonctions de Kernel32.dll du W2k ne fonction pas sur Wnt, donc je n'obtiens pas le même résultat.
    comment faire pour que ces fonctions tournent sur Wnt.

  2. #2
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

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

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    salut
    je suis etonne que tu rencontres ce genre de pb .
    soit plus precis sur les pb rencontres.


  3. #3
    Futur Membre du Club
    Inscrit en
    Janvier 2004
    Messages
    15
    Détails du profil
    Informations forums :
    Inscription : Janvier 2004
    Messages : 15
    Points : 9
    Points
    9
    Par défaut
    en fait j'utilise CreateToolhelp32Snapshot qui est dans kernel32.lib de Tlhelp32.h de W2k et pas celui de Wnt donc je ne peux pas utiliser ses fonctions : th32ParentProcessID de la structure PROCESSENTRY32.

    ce ke g veux c'est créer 1 exécutable qui conserve la dll de W2k.

  4. #4
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

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

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    tjrs pas net pour moi cette fonction est dispo de 95 à XP en passant par 2000.

  5. #5
    Futur Membre du Club
    Inscrit en
    Janvier 2004
    Messages
    15
    Détails du profil
    Informations forums :
    Inscription : Janvier 2004
    Messages : 15
    Points : 9
    Points
    9
    Par défaut
    si j'utilise cette fonction sur Wnt, j'obtiens le message le point d'entrée Process32First de la librairie kernel32.dll n'a pas été trouvé.
    Pour ne pas avoir ce mesaage g le code suivant :

    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
     
    static BOOL IsToolHelpSupported()
    {
    	BOOL    bResult(FALSE);
    	HMODULE hModToolHelp;
    	PROC    pfnCreateToolhelp32Snapshot;
     
    	hModToolHelp = ::LoadLibrary("KERNEL32.DLL");
    	if (NULL != hModToolHelp)
    	{
    		pfnCreateToolhelp32Snapshot = ::GetProcAddress(
    			hModToolHelp, "CreateToolhelp32Snapshot");
    		bResult = (NULL != pfnCreateToolhelp32Snapshot);
    		::FreeLibrary(hModToolHelp);
    	}
    	return bResult;
    }
     
    //---------------------------------------------------------------------------
    // IsPsapiSupported
    //
    // Checks whether PSAPI dll has been installed
    //---------------------------------------------------------------------------
    static BOOL IsPsapiSupported()
    {
    	BOOL bResult = FALSE;
    	HMODULE hModPSAPI = NULL;
     
    	hModPSAPI = ::LoadLibrary("PSAPI.DLL");
    	bResult = (NULL != hModPSAPI);
    	if (NULL != hModPSAPI)
    		::FreeLibrary(hModPSAPI);
     
    	return bResult;
    }
     
     
    CTaskManager::CTaskManager():
    	m_pLibHandler(NULL)
    {
    	m_pProcesses = new CRunningProcesses();
     
    	if (IsToolHelpSupported())
    	{
    		printf("Utilisation de ToolHelp\n");  //ajout david
    		m_pLibHandler = new CToolhelpHandler(m_pProcesses);
    	}
    	else
    	if (IsPsapiSupported())
    	{
    		printf("Utilisatin de Psapi.dll\n");  //ajout david
    		m_pLibHandler = new CPsapiHandler(m_pProcesses);
    	}
     
    }
    donc avec ce code sous Wnt g n'ai ke psapi.dll de supporté

  6. #6
    fd
    fd est déconnecté
    Membre habitué
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    131
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2002
    Messages : 131
    Points : 162
    Points
    162
    Par défaut
    Exact : pas de toolhelp sur nt 4

    Cherche list.c dans le msdn la technique pour nt 4 y est (c'est un scan du registry)

  7. #7
    Futur Membre du Club
    Inscrit en
    Janvier 2004
    Messages
    15
    Détails du profil
    Informations forums :
    Inscription : Janvier 2004
    Messages : 15
    Points : 9
    Points
    9
    Par défaut
    oui g l'ai déjà chercher mais sans succès, tout ce que je trouve ce sont des explication dessus.
    g vais continuez encore pour voir

  8. #8
    fd
    fd est déconnecté
    Membre habitué
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    131
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2002
    Messages : 131
    Points : 162
    Points
    162
    Par défaut
    c'est tlist.c et pas list

    voila la routine

    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
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
     
    DWORD
    GetTaskListNT(
        PTASK_LIST  pTask,
        DWORD       dwNumTasks
        )
     
    /*++
     
    Routine Description:
     
        Provides an API for getting a list of tasks running at the time of the
        API call.  This function uses the registry performance data to get the
        task list and is therefore straight WIN32 calls that anyone can call.
     
    Arguments:
     
        dwNumTasks       - maximum number of tasks that the pTask array can hold
     
    Return Value:
     
        Number of tasks placed into the pTask array.
     
    --*/
     
    {
        DWORD                        rc;
        HKEY                         hKeyNames;
        DWORD                        dwType;
        DWORD                        dwSize;
        LPBYTE                       buf = NULL;
        CHAR                         szSubKey[1024];
        LANGID                       lid;
        LPSTR                        p;
        LPSTR                        p2;
        PPERF_DATA_BLOCK             pPerf;
        PPERF_OBJECT_TYPE            pObj;
        PPERF_INSTANCE_DEFINITION    pInst;
        PPERF_COUNTER_BLOCK          pCounter;
        PPERF_COUNTER_DEFINITION     pCounterDef;
        DWORD                        i;
        DWORD                        dwProcessIdTitle;
        DWORD                        dwProcessIdCounter;
        CHAR                         szProcessName[MAX_PATH];
        DWORD                        dwLimit = dwNumTasks - 1;
     
     
     
        //
        // Look for the list of counters.  Always use the neutral
        // English version, regardless of the local language.  We
        // are looking for some particular keys, and we are always
        // going to do our looking in English.  We are not going
        // to show the user the counter names, so there is no need
        // to go find the corresponding name in the local language.
        //
        lid = MAKELANGID( LANG_ENGLISH, SUBLANG_NEUTRAL );
        sprintf( szSubKey, "%s\\%03x", REGKEY_PERF, lid );
        rc = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
                           szSubKey,
                           0,
                           KEY_READ,
                           &hKeyNames
                         );
        if (rc != ERROR_SUCCESS) {
            goto exit;
        }
     
        //
        // get the buffer size for the counter names
        //
        rc = RegQueryValueEx( hKeyNames,
                              REGSUBKEY_COUNTERS,
                              NULL,
                              &dwType,
                              NULL,
                              &dwSize
                            );
     
        if (rc != ERROR_SUCCESS) {
            goto exit;
        }
     
        //
        // allocate the counter names buffer
        //
        buf = (LPBYTE) malloc( dwSize );
        if (buf == NULL) {
            goto exit;
        }
        memset( buf, 0, dwSize );
     
        //
        // read the counter names from the registry
        //
        rc = RegQueryValueEx( hKeyNames,
                              REGSUBKEY_COUNTERS,
                              NULL,
                              &dwType,
                              buf,
                              &dwSize
                            );
     
        if (rc != ERROR_SUCCESS) {
            goto exit;
        }
     
        //
        // now loop thru the counter names looking for the following counters:
        //
        //      1.  "Process"           process name
        //      2.  "ID Process"        process id
        //
        // the buffer contains multiple null terminated strings and then
        // finally null terminated at the end.  the strings are in pairs of
        // counter number and counter name.
        //
     
        p = buf;
        while (*p) {
            if (p > buf) {
                for( p2=p-2; isdigit(*p2); p2--) ;
                }
            if (stricmp(p, PROCESS_COUNTER) == 0) {
                //
                // look backwards for the counter number
                //
                for( p2=p-2; isdigit(*p2); p2--) ;
                strcpy( szSubKey, p2+1 );
            }
            else
            if (stricmp(p, PROCESSID_COUNTER) == 0) {
                //
                // look backwards for the counter number
                //
                for( p2=p-2; isdigit(*p2); p2--) ;
                dwProcessIdTitle = atol( p2+1 );
            }
            //
            // next string
            //
            p += (strlen(p) + 1);
        }
     
        //
        // free the counter names buffer
        //
        free( buf );
     
     
        //
        // allocate the initial buffer for the performance data
        //
        dwSize = INITIAL_SIZE;
        buf = malloc( dwSize );
        if (buf == NULL) {
            goto exit;
        }
        memset( buf, 0, dwSize );
     
     
        while (TRUE) {
     
            rc = RegQueryValueEx( HKEY_PERFORMANCE_DATA,
                                  szSubKey,
                                  NULL,
                                  &dwType,
                                  buf,
                                  &dwSize
                                );
     
            pPerf = (PPERF_DATA_BLOCK) buf;
     
            //
            // check for success and valid perf data block signature
            //
            if ((rc == ERROR_SUCCESS) &&
                (dwSize > 0) &&
                (pPerf)->Signature[0] == (WCHAR)'P' &&
                (pPerf)->Signature[1] == (WCHAR)'E' &&
                (pPerf)->Signature[2] == (WCHAR)'R' &&
                (pPerf)->Signature[3] == (WCHAR)'F' ) {
                break;
            }
     
            //
            // if buffer is not big enough, reallocate and try again
            //
            if (rc == ERROR_MORE_DATA) {
                dwSize += EXTEND_SIZE;
                buf = realloc( buf, dwSize );
                memset( buf, 0, dwSize );
            }
            else {
                goto exit;
            }
        }
     
        //
        // set the perf_object_type pointer
        //
        pObj = (PPERF_OBJECT_TYPE) ((DWORD)pPerf + pPerf->HeaderLength);
     
        //
        // loop thru the performance counter definition records looking
        // for the process id counter and then save its offset
        //
        pCounterDef = (PPERF_COUNTER_DEFINITION) ((DWORD)pObj + pObj->HeaderLength);
        for (i=0; i<(DWORD)pObj->NumCounters; i++) {
            if (pCounterDef->CounterNameTitleIndex == dwProcessIdTitle) {
                dwProcessIdCounter = pCounterDef->CounterOffset;
                break;
            }
            pCounterDef++;
        }
     
        dwNumTasks = min( dwLimit, (DWORD)pObj->NumInstances );
     
        pInst = (PPERF_INSTANCE_DEFINITION) ((DWORD)pObj + pObj->DefinitionLength);
     
        //
        // loop thru the performance instance data extracting each process name
        // and process id
        //
        for (i=0; i<dwNumTasks; i++) {
            //
            // pointer to the process name
            //
            p = (LPSTR) ((DWORD)pInst + pInst->NameOffset);
     
            //
            // convert it to ascii
            //
            rc = WideCharToMultiByte( CP_ACP,
                                      0,
                                      (LPCWSTR)p,
                                      -1,
                                      szProcessName,
                                      sizeof(szProcessName),
                                      NULL,
                                      NULL
                                    );
     
            if (!rc) {
                //
    	    // if we cant convert the string then use a default value
                //
                strcpy( pTask->ProcessName, UNKNOWN_TASK );
            }
     
            if (strlen(szProcessName)+4 <= sizeof(pTask->ProcessName)) {
                strcpy( pTask->ProcessName, szProcessName );
                strcat( pTask->ProcessName, ".exe" );
            }
     
            //
            // get the process id
            //
            pCounter = (PPERF_COUNTER_BLOCK) ((DWORD)pInst + pInst->ByteLength);
            pTask->flags = 0;
            pTask->dwProcessId = *((LPDWORD) ((DWORD)pCounter + dwProcessIdCounter));
            if (pTask->dwProcessId == 0) {
                pTask->dwProcessId = (DWORD)-2;
            }
     
            //
            // next process
            //
            pTask++;
            pInst = (PPERF_INSTANCE_DEFINITION) ((DWORD)pCounter + pCounter->ByteLength);
        }
     
    exit:
        if (buf) {
            free( buf );
        }
     
        RegCloseKey( hKeyNames );
        RegCloseKey( HKEY_PERFORMANCE_DATA );
     
        return dwNumTasks;
    }

  9. #9
    Rédacteur/Modérateur
    Avatar de Trap D
    Profil pro
    Inscrit en
    Septembre 2003
    Messages
    4 942
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 4 942
    Points : 6 498
    Points
    6 498
    Par défaut
    des Goto dans du C++, je rêve
    "La haine seule fait des choix" - Koan Zen
    "Il ne faut pas être meilleur que les autres, il faut être meilleur que soi." Albert Jacquard
    "Ceux qui savent où ils ont posé leur parapluie ne sont pas alcooliques." - pgibonne.
    Faites du Prolog, ça vous changera les idées !
    Ma page Prolog
    Mes codes sources commentés

    Mon avatar : La Madeleine à la veilleuse de Georges de La Tour

  10. #10
    Futur Membre du Club
    Inscrit en
    Janvier 2004
    Messages
    15
    Détails du profil
    Informations forums :
    Inscription : Janvier 2004
    Messages : 15
    Points : 9
    Points
    9
    Par défaut
    Merci à fd, je testerai ce bou de code lundi.

  11. #11
    Futur Membre du Club
    Inscrit en
    Janvier 2004
    Messages
    15
    Détails du profil
    Informations forums :
    Inscription : Janvier 2004
    Messages : 15
    Points : 9
    Points
    9
    Par défaut
    la routine fournie par fd fonctionnne avec quelques retouche,
    mais il m'est toujours impossible d'obtenir la parentProcessId.
    la variable de pTask->dwInheritedFromProcessId n'est pas initialisée.

  12. #12
    Futur Membre du Club
    Inscrit en
    Janvier 2004
    Messages
    15
    Détails du profil
    Informations forums :
    Inscription : Janvier 2004
    Messages : 15
    Points : 9
    Points
    9
    Par défaut renvoi à un autre intitulé
    renvoi à la question sur la recherche du code de Tlist.c pour Win NT 4.0

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [DLL] utiliser une DLL a partir d' une DLL et un .def
    Par venomelektro dans le forum MFC
    Réponses: 9
    Dernier message: 07/12/2004, 14h01
  2. [FORMS] Utilisation de DLL avec ORA_FFI
    Par Nounoursonne dans le forum Forms
    Réponses: 2
    Dernier message: 07/12/2004, 09h19
  3. utilisation de dll avec diverses compilateurs
    Par Thylia dans le forum C++
    Réponses: 30
    Dernier message: 21/10/2004, 16h30
  4. Utilisation de dll
    Par portu dans le forum Windows
    Réponses: 7
    Dernier message: 02/03/2004, 23h09
  5. [CR] Infos sur l'utilisation de dll
    Par step dans le forum SAP Crystal Reports
    Réponses: 11
    Dernier message: 09/08/2002, 11h35

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