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 :

Utilisation dll - visual studio 2008 - c++


Sujet :

Windows

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 14
    Points : 7
    Points
    7
    Par défaut Utilisation dll - visual studio 2008 - c++
    Bonjour,

    J'ai une carte de contrôle pour 2 moteurs avec cette carte, j'ai un .dll et un .h pour pouvoir contrôler ces moteurs.
    Mais je débute en programmation et je n'arrive pas à créer un programme chargeant le .dll et à en utiliser les fonctions.

    Voici mon bout de programme en win32 console application:

    Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
     
    ///////////////////////////////////////////////////////////////////////////////////////
    #include "stdafx.h"
    #include "E:\Stage_robot\Stepper Bee +\stp.h"
     
     
    int _tmain(int argc, _TCHAR* argv[])
    {
     
    HINSTANCE HStpDll; // declaration of variable to hold the handle to the dll
    HStpDll = LoadLibrary(“stp.dll”); // load the dll into memory and return handle
     
    	return 0;
    }
    ///////////////////////////////////////////////////////////////////////////////////////

    Pour l'instant je veux juste charger la dll et voici les erreurs que je reçois:

    1>------ Build started: Project: stpApp, Configuration: Debug Win32 ------
    1>Compiling...
    1>stpApp.cpp

    1>c:\users\fabien\documents\visual studio 2008\projects\programme\motors\motors\stpapp.cpp(11) : error C2065: 'HINSTANCE' : undeclared identifier

    1>c:\users\fabien\documents\visual studio 2008\projects\programme\motors\motors\stpapp.cpp(11) : error C2146: syntax error : missing ';' before identifier 'HStpDll'

    1>c:\users\fabien\documents\visual studio 2008\projects\programme\motors\motors\stpapp.cpp(11) : error C2065: 'HStpDll' : undeclared identifier

    1>c:\users\fabien\documents\visual studio 2008\projects\programme\motors\motors\stpapp.cpp(12) : error C2065: 'HStpDll' : undeclared identifier

    1>c:\users\fabien\documents\visual studio 2008\projects\programme\motors\motors\stpapp.cpp(12) : error C2065: '“stp' : undeclared identifier

    1>c:\users\fabien\documents\visual studio 2008\projects\programme\motors\motors\stpapp.cpp(12) : error C2228: left of '.dll”' must have class/struct/union
    1> type is ''unknown-type''

    1>c:\users\fabien\documents\visual studio 2008\projects\programme\motors\motors\stpapp.cpp(12) : error C3861: 'LoadLibrary': identifier not found
    1>Build log was saved at "file://c:\Users\Fabien\Documents\Visual Studio 2008\Projects\Programme\Motors\Motors\Debug\BuildLog.htm"
    1>stpApp - 7 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Si quelqu'un pouvait m'aider car je n'arrive pas à corriger mes erreurs.

    Merci d'avance

    Fab

  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
    Bonjour,

    au vu des erreurs, il te manque l'inclusion de l'en-tête windows.h

    Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    #include <windows.h>

    Tu peux le mettre soit :

    - sous l'include de "stdafx.h" (visible seulement depuis le fichier ayant le "main")
    - dans stdafx.h (visible depuis tout les fichier code incluant "stdafx.h")


    Deuxième point :

    attention à la compilation en unicode ou ASCII. Il vaut mieux entourer les chaînes avec la macro _T ou la macro TEXT :

    Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    HStpDll = LoadLibrary(_T("stp.dll")); // load the dll into memory and return handle

    Ainsi, si tu compiles avec UNICODE défini, la chaîne est en unicode, sinon en ASCII.

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

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

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 381
    Points : 41 582
    Points
    41 582
    Par défaut
    Et fais attention à tes guillemets, aussi.

  4. #4
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 14
    Points : 7
    Points
    7
    Par défaut
    Merci à vous deux pour votre aide, celà m'a permis d'avancer.

    Cependant, j'ai des erreurs de débuggage, j'ai beau regarder sur différents forum, je ne trouve rien pour m'aider.
    Voici mon programme:
    Code c++ : 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
     ///////////////////////////////////////////////////////////////////////////////////////
    // Motors.cpp : Defines the entry point for the console application.
    //
     
    #include "stdafx.h"
    #include "E:\Stage_robot\Stepper Bee +\stp.h" 
    #include <windows.h>
     
     
     
    int _tmain(int argc, _TCHAR* argv[])
    {
     
    HINSTANCE HStpDll; // declaration of variable to hold the handle to the dll
    HStpDll = LoadLibrary( _T("stp.dll")); // load the dll into memory and return handle
     
    Type_InitStp InitStp;
    Type_RunMotor1 RunMotor1;
    Type_StopMotor1 StopMotor1;
    Type_RunMotor2 RunMotor2;
    Type_StopMotor2 StopMotor2;
    Type_SetStepMode SetStepMode;
    Type_GetCurrentStatus GetCurrentStatus;
     
    InitStp = (Type_InitStp)GetProcAddress( HStpDll, "InitStp");
    RunMotor1 = (Type_RunMotor1)GetProcAddress( HStpDll, "RunMotor1");
    RunMotor2 = (Type_RunMotor2)GetProcAddress( HStpDll, "RunMotor2");
    StopMotor1 = (Type_StopMotor1)GetProcAddress( HStpDll, "StopMotor1");
    StopMotor2 = (Type_StopMotor2)GetProcAddress( HStpDll, "StopMotor2");
    SetStepMode = (Type_SetStepMode)GetProcAddress( HStpDll, "SetStepMode");
    GetCurrentStatus = (Type_GetCurrentStatus)GetProcAddress(HStpDll,"GetCurrentStatus");
     
     
    InitStp();
    RunMotor1 (2000, 50, 0, 0);
     
    return 0;
    }
     
    ///////////////////////////////////////////////////////////////////////////////////////
    Voici les erreurs qui s'affichent et je comprend pas d'où elles peuvent venir.
    Car j'ai vérifié le fichier .dll, et je ne pense pas me tromper de convention pour appeler la fonction.

    Mes erreurs:

    Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

    First-chance exception at 0x00000000 in stpApp.exe: 0xC0000005: Access violation.

    Unhandled exception at 0x00000000 in stpApp.exe: 0xC0000005: Access violation.

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

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

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 381
    Points : 41 582
    Points
    41 582
    Par défaut
    Les fonctions de la DLL doivent être en __stdcall, alors que tes types de pointeurs sont en __cdecl, ou bien l'inverse...

  6. #6
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 14
    Points : 7
    Points
    7
    Par défaut
    Citation Envoyé par Médinoc Voir le message
    Les fonctions de la DLL doivent être en __stdcall, alors que tes types de pointeurs sont en __cdecl, ou bien l'inverse...
    Merci pour cette réponse, mais je dois t'avouer que je n'y comprend pas grand chose.
    Que dois-je faire avec __stdcall et __cdecl ?
    Dois-je redéfinir mes fonctions (je ne peux pas toucher à la dll car elle m'a été fournie!)?

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

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

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 381
    Points : 41 582
    Points
    41 582
    Par défaut
    Les typedefs, ils sont fournis avec la DLL, ou tu as du les écrire toi-même ?

    Puis-je voir le contenu du fichier d'en-tête de la DLL?

  8. #8
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 14
    Points : 7
    Points
    7
    Par défaut
    Les typedefs je les écrit moi même, j'ai suivi la documentation fourni avec la carte de contrôle du moteur.
    Je ne peux pas accéder au fichiers d'entête de la dll, quand j'essaie de l'ouvrir, j'ai différents fichiers mais rien qui ressemble à un fichier d'entête.

  9. #9
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 14
    Points : 7
    Points
    7
    Par défaut
    Pardon, c'est peu être ce fichier d'entête que tu veux:

    // Header file for use with stp.dll

    typedef int (*Type_InitStp)();
    typedef bool (*Type_RunMotor1)(int steps, int interval, int direction, int outputs);
    typedef bool (*Type_StopMotor1)(int outputs);
    typedef bool (*Type_RunMotor2)(int steps, int interval, int direction, int outputs);
    typedef bool (*Type_StopMotor2)(int outputs);
    typedef bool (*Type_SetStepMode)(int M1Mode, int M2Mode);
    typedef bool (*Type_GetCurrentStatus)(int *M1Active, int *M2Active, int *M1Steps, int *M2Steps, int *Inputs);

  10. #10
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 14
    Points : 7
    Points
    7
    Par défaut
    Hop là, j'ai trouvé la solution à mon problème !

    Grâce à toi Médinoc, en me demandant mon fichier d'entête, car j'ai quand tu m'as parlé de __stdcall et de __cdecl, j'ai vu qu'il fallait modifié un fichier sur d'autre forum mais je comprennais pas lequel. Et en fait c'est le fichier d'entête soit le .h
    Donc j'ai rajouté __stdcall là où il fallait et comme il fallait et mes moteurs tournent

    Merci de votre aide

    Fab

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

Discussions similaires

  1. Utilisation d'une dll dans un projet Visual Studio 2008 [C#]
    Par rhoblik dans le forum Visual Studio
    Réponses: 2
    Dernier message: 19/06/2014, 15h16
  2. Utilisation d'une DLL sous visual studio 2008
    Par MacCallahan dans le forum Bibliothèques
    Réponses: 0
    Dernier message: 01/12/2013, 13h10
  3. Utilisation DLL Visual Studio.NET dans BDS 2009
    Par Zugg dans le forum Langage
    Réponses: 7
    Dernier message: 17/07/2009, 09h32
  4. Création DLL Visual Studio 2008 : Chargement impossible
    Par Bleys dans le forum Visual Studio
    Réponses: 0
    Dernier message: 07/08/2008, 11h03
  5. problème de DLL sous visual studio 2008
    Par kira09 dans le forum C++
    Réponses: 2
    Dernier message: 12/06/2008, 12h50

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