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

Windows Discussion :

[DDK] error LNK2019: unresolved external symbol


Sujet :

Windows

  1. #1
    Membre éclairé Avatar de sloshy
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Janvier 2005
    Messages
    728
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Janvier 2005
    Messages : 728
    Points : 723
    Points
    723
    Par défaut [DDK] error LNK2019: unresolved external symbol
    Bonsoir,
    Par pure "envie" j'ai décidé de comparer les différents compilateurs que j'avais sous la main pour un petit bench des perfs au niveau des exécutables générés.
    Tout se passe merveilleusement bien, quand j'arrive au DDK de windows.

    SOURCE:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    TARGETNAME=app_bench
    TARGETPATH=OBJ
    TARGETTYPE=PROGRAM
    SOURCES=app.c
    MAKEFILE:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    !INCLUDE $(NTMAKEENV)\makefile.def
    app.c
    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
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    BOOL InstallDriver(IN SC_HANDLE SchSCManager, IN LPCTSTR DriverName, IN LPCTSTR ServiceExe);
    BOOL RemoveDriver(IN SC_HANDLE SchSCManager, IN LPCTSTR DriverName);
    BOOL StartDriver(IN SC_HANDLE SchSCManager, IN LPCTSTR DriverName);
    BOOL StopDriver(IN SC_HANDLE SchSCManager, IN LPCTSTR DriverName);
    BOOL OpenDevice(IN LPCTSTR DriverName);
    
    void __cdecl main(IN int argc, IN char *argv[])
    {
        SC_HANDLE schSCManager =NULL;
        if(argc != 3)
        {
            printf("usage:\n");
            printf("\t instdrv <driver name> <.sys location>\n");
            printf("\t instdrv <driver name> remove\n\n");
            exit(1);
        }
    
        schSCManager =OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
        if(!_stricmp(argv[2], "remove"))
        {
            StopDriver(schSCManager, argv[1]);
            RemoveDriver(schSCManager, argv[1]);
        }
        else
        {
            InstallDriver(schSCManager, argv[1], argv[2]);
            StartDriver(schSCManager, argv[1]);
            OpenDevice(argv[1]);
        }
        CloseServiceHandle(schSCManager);
    }
    
    BOOL InstallDriver(IN SC_HANDLE SchSCManager, IN LPCTSTR DriverName, IN LPCTSTR ServiceExe)
    {
        SC_HANDLE schService =NULL;
        DWORD err;
    
        schService = CreateService (SchSCManager, DriverName, DriverName, SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER,
                                    SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, ServiceExe, NULL, NULL, NULL, NULL, NULL);
        if(schService == NULL)
        {
            err =GetLastError();
            if(err == ERROR_SERVICE_EXISTS){printf("failure: CreateService, ERROR_SERVICE_EXISTS\n");}
            else{printf("failure: CreateService (0x%02x)\n", err);}
            return FALSE;
        }
        else{printf("CreateService SUCCESS\n");}
    
        CloseServiceHandle(schService);
        return TRUE;
    }
    
    BOOL RemoveDriver(IN SC_HANDLE SchSCManager, IN LPCTSTR DriverName)
    {
        SC_HANDLE schService =NULL;
        BOOL ret;
    
        schService =OpenService(SchSCManager, DriverName, SERVICE_ALL_ACCESS);
        if(schService == NULL)
        {
            printf("failure: OpenService (0x%02x)\n", GetLastError());
            return FALSE;
        }
    
        ret =DeleteService(schService);
        if(ret){printf("DeleteService SUCCESS\n");}
        else{printf("failure: DeleteService (0x%02x)\n", GetLastError());}
        CloseServiceHandle(schService);
        return ret;
    }
    
    BOOL StartDriver(IN SC_HANDLE SchSCManager, IN LPCTSTR DriverName)
    {
        SC_HANDLE schService =NULL;
        BOOL ret;
        DWORD err;
    
        schService =OpenService(SchSCManager, DriverName, SERVICE_ALL_ACCESS);
        if(schService == NULL)
        {
            printf("failure: OpenService (0x%02x)\n", GetLastError());
            return FALSE;
        }
    
        ret =StartService(schService, 0, NULL);
        if(ret){printf("StartService SUCCESS\n");}
        else
        {
            err =GetLastError();
            if(err == ERROR_SERVICE_ALREADY_RUNNING){printf("failure: StartService, ERROR_SERVICE_ALREADY_RUNNING\n");}
            else{printf("failure: StartService (0x%02x)\n", err);}
        }
        CloseServiceHandle(schService);
        return ret;
    }
    
    BOOL StopDriver(IN SC_HANDLE SchSCManager, IN LPCTSTR DriverName)
    {
        SC_HANDLE schService =NULL;
        BOOL ret;
        SERVICE_STATUS serviceStatus;
    
        schService =OpenService(SchSCManager, DriverName, SERVICE_ALL_ACCESS);
        if (schService == NULL)
        {
            printf("failure: OpenService (0x%02x)\n", GetLastError());
            return FALSE;
        }
    
        ret =ControlService(schService, SERVICE_CONTROL_STOP, &serviceStatus);
        if (ret){printf("ControlService SUCCESS\n");}
        else{printf("failure: ControlService (0x%02x)\n", GetLastError());}
    
        CloseServiceHandle(schService);
        return ret;
    }
    
    BOOL OpenDevice(IN LPCTSTR DriverName)
    {
        char completeDeviceName[64] = "";
        LPCTSTR dosDeviceName =DriverName;
        HANDLE hDevice =NULL;
        BOOL ret;
    
        strcat(completeDeviceName, "\\\\.\\");
        strcat(completeDeviceName, dosDeviceName);
        hDevice =CreateFile(completeDeviceName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
        if (hDevice == ((HANDLE)-1))
        {
            printf("Can't get a handle to %s\n", completeDeviceName);
            ret =FALSE;
        }
    
        else
        {
            printf("CreateFile SUCCESS\n");
            CloseHandle(hDevice);
            ret =TRUE;
        }
        return ret;
    }


    Sortie du build
    :
    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
    C:\Espace_dev\ring3>build
    BUILD: Adding /Y to COPYCMD so xcopy ops won't hang.
    BUILD: Object root set to: ==> objchk_wxp_x86
    BUILD: Compile and Link for i386
    BUILD: Loading C:\WINDDK\3790~1.183\build.dat...
    BUILD: Computing Include file dependencies:
    BUILD: Examining c:\espace_dev\ring3 directory for files to compile.
    BUILD: Saving C:\WINDDK\3790~1.183\build.dat...
    BUILD: Linking c:\espace_dev\ring3 directory
    Linking Executable - objchk_wxp_x86\i386\app.exe for i386
    errors in directory c:\espace_dev\ring3
    app.obj : error LNK2019: unresolved external symbol __imp__CloseServiceHandle@4
    referenced in function _main
    app.obj : error LNK2019: unresolved external symbol __imp__OpenSCManagerA@12 ref
    erenced in function _main
    app.obj : error LNK2019: unresolved external symbol _exit referenced in function
     _main
    app.obj : error LNK2019: unresolved external symbol _printf referenced in functi
    on _main
    app.obj : error LNK2019: unresolved external symbol __imp__GetLastError@0 refere
    nced in function _InstallDriver@12
    app.obj : error LNK2019: unresolved external symbol __imp__CreateServiceA@52 ref
    erenced in function _InstallDriver@12
    app.obj : error LNK2019: unresolved external symbol __imp__DeleteService@4 refer
    enced in function _RemoveDriver@8
    app.obj : error LNK2019: unresolved external symbol __imp__OpenServiceA@12 refer
    enced in function _RemoveDriver@8
    app.obj : error LNK2019: unresolved external symbol __imp__StartServiceA@12 refe
    renced in function _StartDriver@8
    app.obj : error LNK2019: unresolved external symbol __imp__ControlService@12 ref
    erenced in function _StopDriver@8
    app.obj : error LNK2019: unresolved external symbol __imp__CloseHandle@4 referen
    ced in function _OpenDevice@4
    app.obj : error LNK2019: unresolved external symbol __imp__CreateFileA@28 refere
    nced in function _OpenDevice@4
    objchk_wxp_x86\i386\app.exe : error LNK1120: 12 unresolved externals
    BUILD: Done
    
        1 executable built - 13 Errors
    
    C:\Espace_dev\ring3>
    J'ai un peu googler, trouver certaines réponses mais aucune ne me permettant de résoudre ce problème.
    Merci de m'aider !

    Amicalement, sloshy
    “La seule révolution possible, c'est d'essayer de s'améliorer soi-même, en espérant que les autres fassent la même démarche. Le monde ira mieux alors.”

  2. #2
    Rédacteur
    Avatar de Neitsa
    Homme Profil pro
    Chercheur sécurité informatique
    Inscrit en
    Octobre 2003
    Messages
    1 041
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Chercheur sécurité informatique

    Informations forums :
    Inscription : Octobre 2003
    Messages : 1 041
    Points : 1 956
    Points
    1 956
    Par défaut
    Salut Sloshy

    Il te manque USE_MSVCRT dans ton sources (ou USE_CRTDLL ou USE_LIBCMT en lieu et place de USE_MSVCRT, mais je préfère cette dernière).

    Un exemple qui devrait compiler :

    SOURCES :
    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
    TARGETNAME=app_bench
    TARGETTYPE=PROGRAM
    
    SOURCES=app.c
    
    UMTYPE=console
    UMBASE=0x04000000
    
    USE_MSVCRT=1
    
    #Un exemple pour utiliser d'autres bibliothèques si jamais tu en as besoin.
    TARGETLIBS=$(SDK_LIB_PATH)\kernel32.lib \
               $(SDK_LIB_PATH)\advapi32.lib \
               $(SDK_LIB_PATH)\user32.lib
    Un petit build -ceZ et ça devrait rouler

    N'oublie pas de jeter un petit coup d'œil sur la MSDN à Build Utility Macros.

  3. #3
    Membre éclairé Avatar de sloshy
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Janvier 2005
    Messages
    728
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Janvier 2005
    Messages : 728
    Points : 723
    Points
    723
    Par défaut
    Hello,
    Merci de ta réponse Neitsa, comme toujours de bon conseil
    Je vais explorer une nouvelle facette de la MSDN

    EDIT://
    ça compile parfaitement, par contre je suis sidéré qu'un exécutable généré avec mingw est 4x plus important en taille qu'avec le DDK alors que je n'ai précisé aucunne optimisation ni pour l'un, ni pour l'autre
    “La seule révolution possible, c'est d'essayer de s'améliorer soi-même, en espérant que les autres fassent la même démarche. Le monde ira mieux alors.”

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

Discussions similaires

  1. error LNK2019: unresolved external symbol
    Par Francixtra dans le forum Visual C++
    Réponses: 4
    Dernier message: 31/03/2011, 02h32
  2. Réponses: 25
    Dernier message: 23/02/2008, 21h35
  3. error LNK2019: unresolved external symbol
    Par ilimo dans le forum C++
    Réponses: 22
    Dernier message: 09/04/2006, 23h59
  4. error LNK2019: unresolved external symbol
    Par soniona dans le forum Autres éditeurs
    Réponses: 2
    Dernier message: 06/04/2006, 14h03
  5. Réponses: 4
    Dernier message: 23/04/2004, 16h06

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