Click here to Skip to main content
15,887,596 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MFC CreateInstance from CWinThread Pin
IAmRami17-May-10 3:31
IAmRami17-May-10 3:31 
GeneralRe: MFC CreateInstance from CWinThread Pin
Code-o-mat17-May-10 3:48
Code-o-mat17-May-10 3:48 
GeneralRe: MFC CreateInstance from CWinThread Pin
IAmRami19-May-10 22:05
IAmRami19-May-10 22:05 
QuestionHow to get all instances of Excel.exe Pin
KTTransfer17-May-10 2:17
KTTransfer17-May-10 2:17 
AnswerRe: EnumWindowsProc( ) , EnumProcessModules , FindWindow( ), Pin
Software_Developer17-May-10 3:00
Software_Developer17-May-10 3:00 
AnswerRe: How to get all instances of Excel.exe Pin
sashoalm17-May-10 5:07
sashoalm17-May-10 5:07 
GeneralRe: How to get all instances of Excel.exe Pin
KTTransfer17-May-10 18:12
KTTransfer17-May-10 18:12 
GeneralRe: How to get all instances of Excel.exe Pin
sashoalm17-May-10 23:33
sashoalm17-May-10 23:33 
This code might help you. Call get_Application function of the obtained document IDispatch to get its application's IDispatch.

void COffCntrDispCtrl::GetDocDispatch()
{
    // No need, if we already have it.
    if(m_pDocDisp != NULL) return;

    // Get a BindCtx.
    IBindCtx *pbc;
    HRESULT hr = CreateBindCtx(0, &pbc);
    if(FAILED(hr)) {
        DoErr("CreateBindCtx()", hr);
        return;
    }

    // Get running-object table.
    IRunningObjectTable *prot;
    hr = pbc->GetRunningObjectTable(&prot);
    if(FAILED(hr)) {
        DoErr("GetRunningObjectTable()", hr);
        pbc->Release();
        return;
    }

    // Get enumeration interface.
    IEnumMoniker *pem;
    hr = prot->EnumRunning(&pem);
    if(FAILED(hr)) {
        DoErr("EnumRunning()", hr);
        prot->Release();
        pbc->Release();
        return;
    }

    // Start at the beginning.
    pem->Reset();

    // Churn through enumeration.
    ULONG fetched;
    IMoniker *pmon;
    int n = 0;
    while(pem->Next(1, &pmon, &fetched) == S_OK) {

        // Get DisplayName.
        LPOLESTR pName;
        pmon->GetDisplayName(pbc, NULL, &pName);
        // Convert it to ASCII.
        char szName[512];
        WideCharToMultiByte(CP_ACP, 0, pName, -1, szName, 512, NULL,
        NULL);

        // Compare it against the name we got in SetHostNames().
        if(!strcmp(szName, m_szDocName)) {

            DoMsg("Found document in ROT!");

            // Bind to this ROT entry.
            IDispatch *pDisp;
            hr = pmon->BindToObject(pbc, NULL, IID_IDispatch, (void
            **)&pDisp);
            if(!FAILED(hr)) {
                // Remember IDispatch.
                m_pDocDisp = pDisp;

                // Notice...
                sprintf(buf, "Document IDispatch = %08lx",
                m_pDocDisp);
                DoMsg(buf);
            }
            else {
                DoErr("BindToObject()", hr);
            }
        }

        // Release interfaces.
        pmon->Release();

        // Break out if we obtained the IDispatch successfully.
        if(m_pDocDisp != NULL) break;
    }

    // Release interfaces.
    pem->Release();
    prot->Release();
    pbc->Release();
}

void COffCntrDispCtrl::TestDispatch()
{
    ASSERT(m_pDocDisp);

    COleDispatchDriver doc(m_pDocDisp);
    DISPID dispID = 0;
    unsigned short *ucPtr = L"Name";

    // Get DISPID for Name.
    HRESULT hr = m_pDocDisp->GetIDsOfNames(IID_NULL, &ucPtr, 1,
    LOCALE_USER_DEFAULT, &dispID);
    ASSERT(!FAILED(hr));


    // Get Name property.
    CString name;
    doc.GetProperty(dispID, VT_BSTR, &name);

    AfxMessageBox(
        CString("Document name is ") + name,
        MB_SETFOREGROUND
    );
}

There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal

GeneralRe: How to get all instances of Excel.exe Pin
T210211-Jan-11 22:00
T210211-Jan-11 22:00 
QuestionHow to register an automation enabled application in the ROT when it's started from the command line. Pin
TClarke17-May-10 0:45
TClarke17-May-10 0:45 
Questionneed help vc++.net please Pin
Gilbertu16-May-10 23:54
Gilbertu16-May-10 23:54 
AnswerRe: need help vc++.net please Pin
Hristo-Bojilov17-May-10 0:09
Hristo-Bojilov17-May-10 0:09 
GeneralRe: need help vc++.net please Pin
Gilbertu17-May-10 0:19
Gilbertu17-May-10 0:19 
QuestionHiding Controls Dynamically in Dialog Pin
Anu_Bala16-May-10 23:40
Anu_Bala16-May-10 23:40 
AnswerRe: Hiding Controls Dynamically in Dialog Pin
Hristo-Bojilov17-May-10 0:59
Hristo-Bojilov17-May-10 0:59 
AnswerRe: Hiding Controls Dynamically in Dialog Pin
Member 392263917-May-10 2:18
Member 392263917-May-10 2:18 
GeneralRe: Hiding Controls Dynamically in Dialog Pin
David Crow17-May-10 3:05
David Crow17-May-10 3:05 
QuestionInput from Commandline. Pin
krishna_CP16-May-10 22:37
krishna_CP16-May-10 22:37 
AnswerRe: Input from Commandline. Pin
Hristo-Bojilov16-May-10 22:44
Hristo-Bojilov16-May-10 22:44 
AnswerRe: Input from Commandline. Pin
Garth J Lancaster16-May-10 23:33
professionalGarth J Lancaster16-May-10 23:33 
AnswerRe: Input from Commandline. Pin
Aescleal17-May-10 1:11
Aescleal17-May-10 1:11 
QuestionWriteprivateprofilestring() take delay to update original ini file Pin
Shivanand Gupta16-May-10 20:56
Shivanand Gupta16-May-10 20:56 
AnswerRe: Writeprivateprofilestring() take delay to update original ini file Pin
Richard MacCutchan16-May-10 21:03
mveRichard MacCutchan16-May-10 21:03 
QuestionRe: Writeprivateprofilestring() take delay to update original ini file Pin
David Crow17-May-10 3:08
David Crow17-May-10 3:08 
Questionwmv blank file creation Pin
mohan_chandra8416-May-10 20:29
mohan_chandra8416-May-10 20:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.