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]Liens Ed2k et CCommandLineInfo


Sujet :

MFC

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    13
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 13
    Points : 12
    Points
    12
    Par défaut [Resolue][MFC]Liens Ed2k et CCommandLineInfo
    Je developpe une application en MFC SDI en relation avec le soft "Emule".
    Je voudrai recupere les liens ed2k (en liens hypertext sous IE ou FireFox ) sous la forme d'une chaine de caractere ( a stocker dans un CString ) pour un traitement par mon programme.
    En fait, lorsque je clique sur un lien ed2k, cela lance mon programme pour apres l'ajouter dans une liste ( CListView ) .

    Mon programme se lance bien lorque je clique sur le lien ed2k, je le stocke bien dans une variable CString mais apres le programme bugue
    Le programme me fait une 'Debug Assertion Failed' dans le fichier 'DocMgr.cpp' Line 926.

    Je pense savoir d'ou vient le problem : en fait le programme pense que ce liens est en fait un fichier a charge et ca fout la zone dans les classes CDocument ou CDocTemplate et CCommandLineInfo.
    Dans un programme en 'Dialog Base' ca marche tres bien

    Par contre je sais pas comment eviter ce plantage - Avez vous une idee ?

    Voila une partie de mon 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
    BOOL CEmuleLinkInjectApp::InitInstance()
    {
    // InitCommonControls() is required on Windows XP if an application
    // manifest specifies use of ComCtl32.dll version 6 or later to enable
    // visual styles. Otherwise, any window creation will fail.
    InitCommonControls();
    CWinApp::InitInstance();
     
    if (!AfxSocketInit())
    {
    AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
    return FALSE;
    }
    // Initialize OLE libraries
    if (!AfxOleInit())
    {
    AfxMessageBox(IDP_OLE_INIT_FAILED);
    return FALSE;
    }
    AfxEnableControlContainer();
    // 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
    // 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(""));
    LoadStdProfileSettings(4); // 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
    
    CSingleDocTemplate* pDocTemplate;
    pDocTemplate = new CSingleDocTemplate(
    IDR_MAINFRAME,
    RUNTIME_CLASS(CEmuleLinkInjectDoc),
    RUNTIME_CLASS(CMainFrame), // main SDI frame window
    RUNTIME_CLASS(CEmuleLinkInjectView));
    if (!pDocTemplate)
    return FALSE;
    AddDocTemplate(pDocTemplate);
    pendinglink = 0;
    if ( GetEmuleLinkInjectRunning() )
    return FALSE;
    // Enable DDE Execute open
    EnableShellOpen();
    RegisterShellFileTypes(TRUE);
    // Load Icons for Tray 
    // m_pMainWnd->SetIcon( ::LoadIcon( m_hInstance, MAKEINTRESOURCE(IDR_MAINFRAME)), TRUE );
    
    Function->LoadOptions();
    Function->HideUnHideApplication( m_pMainWnd, (EmuleLinkInjectOptions->bAppWindowsStart || EmuleLinkInjectOptions->bHideAppOnStartup) );
     
    COpenInternet OpenInternet;
    if ( OpenInternet.GetSession() == NULL )
    {
    EmuleLinkInjectVariableApp->bConnectToEmuleState = false;
    }
    // create a new (empty) document
    // OnFileNew();
    // The one and only window has been initialized, so show and update it
    m_pMainWnd->UpdateWindow();
    // call DragAcceptFiles only if there's a suffix
    // In an SDI app, this should occur after ProcessShellCommand
    // Enable drag/drop open
    m_pMainWnd->DragAcceptFiles();
    return TRUE;
    }
    
    ET le les cles a rajouter dans la base de registre :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    Windows Registry Editor Version 5.00
    [HKEY_CLASSES_ROOT\ed2k]
    @="URL: ed2k Protocol"
    "URL Protocol"=""
    [HKEY_CLASSES_ROOT\ed2k\DefaultIcon]
    @="c:\\Documents and Settings\\Administrateur\\Mes documents\\Visual Studio Projects\\EmuleLinkInject\\Debug\\EmuleLinkInject.exe"
    [HKEY_CLASSES_ROOT\ed2k\shell]
    [HKEY_CLASSES_ROOT\ed2k\shell\open]
    [HKEY_CLASSES_ROOT\ed2k\shell\open\command]
    @="\"c:\\Documents and Settings\\Administrateur\\Mes documents\\Visual Studio Projects\\EmuleLinkInject\\Debug\\EmuleLinkInject.exe\" \"%1\""
    Si vous avez besion de toutes les sources de mon projet, je peut vous les fournir...

    Please Help Me, je pete un plomb
    J'espere vous avoir pas trop prit la tete - Merci de vos reponses...

  2. #2
    Rédacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414
    Points : 16 075
    Points
    16 075
    Par défaut
    salut,
    tu peux peut-etre t'inspirer de ce post http://www.developpez.net/forums/sho...7&postcount=62

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    13
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 13
    Points : 12
    Points
    12
    Par défaut Solution
    Merci nico-pyright(c), je me suis inspire de ce post : http://www.developpez.net/forums/sho...7&postcount=62 , cela permet d'eviter "l'assertion failed" dans le fichier 'Docmgr.cpp' en desactivant le traitement MFC d'un fichier CDocument.

    Et de cette faq : http://c.developpez.com/faq/vc/?page...GetCommandLine pour enfin resoudre mon probleme.
    En fait, je recupe le lien ed2k avec la command AfxGetApp()->m_lpCmdLine . C'est simple, mais il fallait y penser

    Mon programme fonctionne parfaitement bien maintenant, ca fait trop de plaisir

    Voila mon code :
    fragment fichier 'EmuleLinkInject.cpp'
    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
    
    BOOL CALLBACK CEmuleLinkInjectApp::SearchEmuleLinkInjectWindow( HWND hWnd, LPARAM lParam )
    {
    DWORD dwMsgResult;
    LRESULT lResult = ::SendMessageTimeout( hWnd, UWM_ARE_YOU_EMULELINKINJECT, 0, 0, SMTO_BLOCK | SMTO_ABORTIFHUNG, 10000, &dwMsgResult);
    if( lResult == NULL )
    return TRUE;
     
    if( dwMsgResult == UWM_ARE_YOU_EMULELINKINJECT )
    { 
    HWND* target = (HWND*)lParam;
    *target = hWnd;
    return FALSE; 
    }
    return TRUE; 
    }
    void CCustumCommandLineInfo::ParseParam(const TCHAR* pszParam,BOOL bFlag,BOOL bLast)
    {
    for (int i = 1; i < __argc; i++)
    {
    LPCTSTR pszParam = __targv[i];
    if (pszParam[0] == _T('-') || pszParam[0] == _T('/'))
    {
    pszParam++;
    if ( strcmp(pszParam, "WinStart") == 0 )
    EmuleLinkInjectOptions->bHideAppOnStartup = true;
    else
    EmuleLinkInjectOptions->bHideAppOnStartup = false;
    if ( strcmp(pszParam, "AddFile") == 0)
    AfxMessageBox( "Do you want Add file ?", MB_ICONQUESTION | MB_YESNO);
    }
    }
    }
    BOOL CEmuleLinkInjectApp::GetEmuleLinkInjectRunning( void )
    {
    // Parse command line for standard shell commands, DDE, file open
    CCustumCommandLineInfo cmdInfo;
    ParseCommandLine(cmdInfo);
    HWND maininst = NULL;
    bool bAlreadyRunning ; 
    m_hMutexOneInstance = ::CreateMutex( NULL, FALSE, _T(EMULELINKINJECT_GUID) );
    bAlreadyRunning = ( ::GetLastError() == ERROR_ALREADY_EXISTS ||::GetLastError() == ERROR_ACCESS_DENIED);
     
    if ( bAlreadyRunning ) 
    EnumWindows(SearchEmuleLinkInjectWindow, (LPARAM)&maininst);
    CString command( AfxGetApp()->m_lpCmdLine );
    if ( !command.IsEmpty() )
    {
    sendstruct.cbData = ( command.GetLength() + 1) * sizeof( TCHAR );
    sendstruct.lpData = command.GetBuffer();
    sendstruct.dwData = ( Function->VerifyLink(command, false) ) ? OP_ED2KLINK : OP_ECOMMAND;
     
    if ( maininst )
    {
    SendMessage( maininst, WM_COPYDATA, (WPARAM)0, (LPARAM) (PCOPYDATASTRUCT) &sendstruct);
    returntrue;
    }
    else
    {
    ProcessShellCommand(cmdInfo);
    AfxGetMainWnd()->SendMessage( WM_COPYDATA, (WPARAM)0, (LPARAM) (PCOPYDATASTRUCT) &sendstruct);
    returnfalse;
    }
    }
    // Dispatch commands specified on the command line. Will return FALSE if
    // app was launched with /RegServer, /Register, /Unregserver or /Unregister.
    ProcessShellCommand(cmdInfo);
     
    return ( maininst || bAlreadyRunning);
    }
    // CEmuleLinkInjectApp initialization
    BOOL CEmuleLinkInjectApp::InitInstance()
    {
    // InitCommonControls() is required on Windows XP if an application
    // manifest specifies use of ComCtl32.dll version 6 or later to enable
    // visual styles. Otherwise, any window creation will fail.
    InitCommonControls();
    CWinApp::InitInstance();
    if (!AfxSocketInit())
    {
    AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
    return FALSE;
    }
    // Initialize OLE libraries
    if (!AfxOleInit())
    {
    AfxMessageBox(IDP_OLE_INIT_FAILED);
    return FALSE;
    }
    AfxEnableControlContainer();
    // 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
    // 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(""));
    LoadStdProfileSettings(4); // 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
    CSingleDocTemplate* pDocTemplate;
    pDocTemplate = new CSingleDocTemplate(
    IDR_MAINFRAME,
    RUNTIME_CLASS(CEmuleLinkInjectDoc),
    RUNTIME_CLASS(CMainFrame), // main SDI frame window
    RUNTIME_CLASS(CEmuleLinkInjectView));
    if (!pDocTemplate)
    return FALSE;
    AddDocTemplate(pDocTemplate);
    // Enable DDE Execute open
    EnableShellOpen();
    RegisterShellFileTypes(TRUE);
     
    pendinglink = 0;
    if ( GetEmuleLinkInjectRunning() )
    {
    return FALSE;
    }
    m_pMainWnd->SetIcon( ::LoadIcon( m_hInstance, MAKEINTRESOURCE(IDR_MAINFRAME)), TRUE );
     
    Function->LoadOptions();
    Function->HideUnHideApplication( m_pMainWnd, (EmuleLinkInjectOptions->bAppWindowsStart || EmuleLinkInjectOptions->bHideAppOnStartup) );
     
    COpenInternet OpenInternet;
    if ( OpenInternet.GetSession() == NULL )
    {
    EmuleLinkInjectVariableApp->bConnectToEmuleState = false;
    }
    /*
    // The one and only window has been initialized, so show and update it
    if ( (EmuleLinkInjectOptions->bAppWindowsStart || EmuleLinkInjectOptions->bHideAppOnStartup) )
    m_pMainWnd->ShowWindow(SW_HIDE);
    else
    m_pMainWnd->ShowWindow(SW_SHOW);
    */
    m_pMainWnd->UpdateWindow();
    // call DragAcceptFiles only if there's a suffix
    // In an SDI app, this should occur after ProcessShellCommand
    // Enable drag/drop open
    m_pMainWnd->DragAcceptFiles();
     
    return TRUE;
    }
    
    fragment du fichier 'EmuleLinkInject.h'
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    
    class CCustumCommandLineInfo : public CCommandLineInfo
    {
    void ParseParam(const TCHAR* pszParam,BOOL bFlag,BOOL bLast);
    };
    
    Petite modif dans les cle de la base de registe :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    Windows Registry Editor Version 5.00
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\ed2k]
    @="URL: ed2k Protocol"
    "URL Protocol"=""
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\ed2k\shell]
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\ed2k\shell\open]
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\ed2k\shell\open\command]
    @="\"C:\\Documents and Settings\\Administrateur\\Mes documents\\Visual Studio Projects\\EmuleLinkInject\\Debug\\EmuleLinkInject.exe\" %1"
    J'espere que ca aidera quelqu'un d'autre

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

Discussions similaires

  1. [C++/CLI] Lien avec MFC sur fenêtre non modale
    Par Tan Phi dans le forum C++/CLI
    Réponses: 1
    Dernier message: 13/04/2010, 15h26
  2. video et lien hypertexte avec MFC
    Par tayourt dans le forum MFC
    Réponses: 4
    Dernier message: 28/04/2007, 00h42
  3. Réponses: 3
    Dernier message: 16/05/2006, 10h32
  4. [MFC] liens hypertexte dans un CRichEditCtrl
    Par hiko-seijuro dans le forum MFC
    Réponses: 1
    Dernier message: 15/06/2005, 12h14
  5. Origine de Visual C++ - lien avec les MFC
    Par drinkmilk dans le forum MFC
    Réponses: 5
    Dernier message: 18/04/2005, 10h47

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