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 :

[MFC] - Chargement d'une dll de ressource et d'une MDI


Sujet :

MFC

  1. #1
    Membre régulier
    Avatar de Alice9
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mai 2004
    Messages : 124
    Points : 85
    Points
    85
    Par défaut [MFC] - Chargement d'une dll de ressource et d'une MDI
    Re hello,

    je suis toujours entrain de me battre avec ma dll de ressource.

    J'ai suivi pas à pas l'article de Farscape dans la FAQ.

    Voici ce que donne ma fonction InitInstance :
    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
     
    #ifdef _AFXDLL
    	Enable3dControls();			// Call this when using MFC in a shared DLL
    #else
    	Enable3dControlsStatic();	// Call this when linking to MFC statically
    #endif
     
       //--------------------------------------------------------------
       // Chargement de la librairie adéquate
     
      // pour l'instant je ne laisse pas le choix de la langue pour mes tests
       WriteProfileInt("Language","SetInFr",true);
     
       m_bFrenchRes=(GetProfileInt("Language","SetInFr",0)==1);
       if(m_bFrenchRes)
       {
          HINSTANCE dll=LoadLibrary("Pilot3D_Fr.dll");
          if(dll) 
          {
             AfxSetResourceHandle(dll);
          }
       }
       //--------------------------------------------------------------
     
    	// Change the registry key under which our settings are stored.
    	// TODO: You should modify this string to be something appropriate
    	// such as the name of your company or organization.
    	SetRegistryKey(_T("Local AppWizard-Generated Applications"));
     
    	LoadStdProfileSettings();  // Load standard INI file options (including MRU)
     
    	// Register the application's document templates.  Document templates
    	//  serve as the connection between documents, frame windows and views.
     
    	CMultiDocTemplate* pDocTemplate;
    	pDocTemplate = new CMultiDocTemplate(
    		IDR_PILOT3TYPE,
    		RUNTIME_CLASS(CPilot3DDoc),
    		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
    		RUNTIME_CLASS(CPilot3DView));
    	AddDocTemplate(pDocTemplate);
     
    	// create main MDI Frame window
    	CMainFrame* pMainFrame = new CMainFrame;
    	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
       {
    		return FALSE;
       }
    	m_pMainWnd = pMainFrame ;
     
    // je n'ai pas de view ni de doc dans cette application
    // je n'ai que des DialogBar ou des boîtes de dialogues classiques
     /* 
    	// Parse command line for standard shell commands, DDE, file open
    	CCommandLineInfo cmdInfo;
    	ParseCommandLine(cmdInfo);
     
    	// Dispatch commands specified on the command line
    	if (!ProcessShellCommand(cmdInfo))
    		return FALSE;
    */
    	// The main window has been initialized, so show and update it.
    	pMainFrame->ShowWindow(m_nCmdShow);
    	pMainFrame->UpdateWindow();
    Mon problème est que tout se passe bien jusqu'au chargement de la ressource IDR_MAINFRAME avec LoadFrame :
    le chargement ne se fait pas et la fonction sort avec un return FALSE.
    (bien entendu ça compile et ça link sans aucun problème).

    Est ce que quelqu'un a déjà rencontré ce problème ?

    Merci

    Alice

  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,
    si ta dll de ressources est identique en tout point à celle d'origine,il ne devrait pas y avoir de pb.

  3. #3
    Membre régulier
    Avatar de Alice9
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mai 2004
    Messages : 124
    Points : 85
    Points
    85
    Par défaut
    Hé bien c'est le cas.....


    t'es sur qu'il n'y a pas autre chose ?

  4. #4
    Membre régulier
    Avatar de Alice9
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mai 2004
    Messages : 124
    Points : 85
    Points
    85
    Par défaut
    :trouve:

    Pour informations, lorsque l'on est en mode MDI il faut :
    d'abord charger la frame avec LoadFrame
    puis charger la DLL de ressource et mettre à jour les ressources

    Cî joint le devenu de ma fonction InitInstance :
    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
     
    {
    	// Standard initialization
    	// If you are not using these features and wish to reduce the size
    	//  of your final executable, you should remove from the following
    	//  the specific initialization routines you do not need.
     
    #ifdef _AFXDLL
    	Enable3dControls();			// Call this when using MFC in a shared DLL
    #else
    	Enable3dControlsStatic();	// Call this when linking to MFC statically
    #endif
     
     
    	// Change the registry key under which our settings are stored.
    	// TODO: You should modify this string to be something appropriate
    	// such as the name of your company or organization.
    	//SetRegistryKey(_T("Local AppWizard-Generated Applications"));
     
    	LoadStdProfileSettings();  // Load standard INI file options (including MRU)
     
    	// Register the application's document templates.  Document templates
    	//  serve as the connection between documents, frame windows and views.
     
    	CMultiDocTemplate* pDocTemplate;
    	pDocTemplate = new CMultiDocTemplate(
    		IDR_PILOT3TYPE,
    		RUNTIME_CLASS(CPilot3DDoc),
    		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
    		RUNTIME_CLASS(CPilot3DView));
    	AddDocTemplate(pDocTemplate);
     
    	// create main MDI Frame window
    	CMainFrame* pMainFrame = new CMainFrame;
    	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
       {
    		return FALSE;
       }
        //--------------------------------------------------------------
       // Chargement de la librairie adéquate
     
       // impose d'utiliser la dll france pour test
       WriteProfileInt("Language","SetInFr",true);
     
       // récupération de la langue choisie
       m_bFrenchRes=(GetProfileInt("Language","SetInFr",0)==1);
       if(m_bFrenchRes)
       {
          // chargement de la librairie
          HINSTANCE dll =LoadLibrary("langue_Fr.dll");
          if(dll) 
          {
             //mise à jour des ressources
             AfxSetResourceHandle(dll);
          }
       }
       //--------------------------------------------------------------
    	m_pMainWnd = pMainFrame ;
     
    // je n'utilise pas de documents dans mon application
     /*
    	// Parse command line for standard shell commands, DDE, file open
    	CCommandLineInfo cmdInfo;
    	ParseCommandLine(cmdInfo);
     
    	// Dispatch commands specified on the command line
    	if (!ProcessShellCommand(cmdInfo))
    		return FALSE;
    */
    	// The main window has been initialized, so show and update it.
    	pMainFrame->ShowWindow(m_nCmdShow);
    	pMainFrame->UpdateWindow();
     
    	return TRUE;
    }
    Et là tout marche à merveille !!!!



    Bon Appétit !!!

    Alice
    --------------------------------------------
    PS : merci Farscape, ça m'a permis d'éliminer certaines interrogations et de me diriger vers la bonne solution.

  5. #5
    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
    tres bien !
    je rajouterais ce point de detail pour le MDI dans la faq.



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

Discussions similaires

  1. Réponses: 1
    Dernier message: 19/12/2010, 01h32
  2. Réponses: 1
    Dernier message: 31/05/2010, 14h38
  3. [DLL] Afficher le contenu d'une dll dans un Tpanel
    Par Fabs dans le forum Composants VCL
    Réponses: 4
    Dernier message: 17/08/2007, 14h30
  4. [MFC][DLL]Dialog Avec ActiveX dans une DLL ?
    Par matazz dans le forum MFC
    Réponses: 1
    Dernier message: 16/05/2005, 16h36
  5. Réponses: 9
    Dernier message: 29/03/2005, 09h36

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