Solved

Using activex controls in win32 (non mfc) dll

Posted on 2003-11-27
12
768 Views
Last Modified: 2013-12-03
Can any one tell me how to use activex control in win32(non mfc) dll.

When I use the activex control in dialog, I get class not found error.

so please if any one can provide sample code for how to use activex control in win32(non mfc)dll
0
Comment
Question by:imti_lak
12 Comments
 
LVL 5

Accepted Solution

by:
Daij-Djan earned 500 total points
ID: 9836971
U need to HOST the control in your own COM container. You need to implement various interfaces.
0
 

Author Comment

by:imti_lak
ID: 9837090
But how to host a control in my own container.

can u give any sample code
0
 
LVL 5

Expert Comment

by:Daij-Djan
ID: 9837183
// MainDlg.cpp : Implementation of CMainDlg
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// Dominik Pich
//

#include "../../stdafx.h"
#include "RemoteHost.h"
#include "Container.h"

/////////////////////////////////////////////////////////////////////////////
// CContainer

//***************************************************************************
// Constructor
//
//***************************************************************************
NAudio::Internal::CContainer::CContainer()
{
    m_pView = NULL;
}

//***************************************************************************
// Destructor
//
//***************************************************************************
NAudio::Internal::CContainer::~CContainer()
{
}

//***************************************************************************
// Init()
// Initialize the dialog and create WMP OCX
//
//***************************************************************************
bool NAudio::Internal::CContainer::Init()
{
    HRESULT                             hr = S_OK;
    HWND                                hWndParent;
    RECT                                rcClient;
    CComPtr<IObjectWithSite>            spHostObject;
    CComPtr<IAxWinHostWindow>           spHost;
    CComObject<CRemoteHost>             *pRemoteHost = NULL;


    // Create an ActiveX control container
    AtlAxWinInit();
    m_pView = new CAxWindow();  
    if(!m_pView)
    {
        hr = E_OUTOFMEMORY;
    }
   
    if(SUCCEEDED(hr))
    {
        hr = E_OUTOFMEMORY;

        hWndParent = FindWindow( _T("icoTrilly"), NULL );
        if(::IsWindow(hWndParent))
        {
            GetClientRect( hWndParent, &rcClient );
            m_pView->Create(hWndParent, rcClient, NULL, WS_CHILD | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE);

            if(::IsWindow(m_pView->m_hWnd))
            {
                hr = m_pView->QueryHost(IID_IObjectWithSite, (void **)&spHostObject);
                      if(!spHostObject.p)
                      {
                            hr = E_POINTER;
                      }
            }
        }
    }

    // Create remote host which implements IServiceProvider and IWMPRemoteMediaServices
    if(SUCCEEDED(hr))
    {
        hr = CComObject<CRemoteHost>::CreateInstance(&pRemoteHost);
        if(pRemoteHost)
        {
            pRemoteHost->AddRef();
        }
            else
            {
                  hr = E_POINTER;
            }
    }

    // Set site to the remote host
    if(SUCCEEDED(hr))
    {
        hr = spHostObject->SetSite((IWMPRemoteMediaServices *)pRemoteHost);
    }

    if(SUCCEEDED(hr))
    {
        hr = m_pView->QueryHost(&spHost);
            if(!spHost.p)
            {
                  hr = E_NOINTERFACE;
            }
    }

    // Create WMP Control here
    if(SUCCEEDED(hr))
    {
        hr = spHost->CreateControl(CComBSTR(L"{6BF52A52-394A-11d3-B153-00C04F79FAA6}"), m_pView->m_hWnd, NULL);
    }

    if(SUCCEEDED(hr))
    {
        hr = m_pView->QueryControl(&m_spPlayer);
            if(!m_spPlayer.p)
            {
                  hr = E_NOINTERFACE;
            }
    }

    // Release remote host object
    if(pRemoteHost)
    {
        pRemoteHost->Release();
    }

    return SUCCEEDED( hr );
}

//***************************************************************************
// Term()
// Release WMP OCX and its container here
//
//***************************************************************************
void NAudio::Internal::CContainer::Term()
{
    m_spPlayer.Release();

    if(m_pView != NULL)
    {
        delete m_pView;
    }
}

// RemoteHost.cpp: implementation of the RemoteHost class.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//

#include "../../stdafx.h"
#include "RemoteHost.h"
#include "stdio.h"
#include "../../resource.h"

/////////////////////////////////////////////////////////////////////////////
// CRemoteHost

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
NAudio::Internal::CRemoteHost::CRemoteHost()
{

}

NAudio::Internal::CRemoteHost::~CRemoteHost()
{

}

//***************************************************************************
// QueryService()
// API from IServiceProvider
//***************************************************************************
HRESULT NAudio::Internal::CRemoteHost::QueryService(REFGUID guidService, REFIID riid, void ** ppv)
{
    return ppv? QueryInterface(riid, ppv) : E_POINTER;
}


//***************************************************************************
// GetServiceType()
// Always return Remote so that the player OCX runs at remote state
//***************************************************************************
HRESULT NAudio::Internal::CRemoteHost::GetServiceType(BSTR * pbstrType)
{
    HRESULT hr = E_POINTER;
    if(pbstrType)
    {
        *pbstrType = ::SysAllocString(L"Remote");
        hr = *pbstrType? S_OK : E_POINTER;
    }
    return hr;
}

//***************************************************************************
// GetApplicationName()
// Return the application name. It will be shown in player's menu View >
// Switch to applications
//***************************************************************************
HRESULT NAudio::Internal::CRemoteHost::GetApplicationName(BSTR * pbstrName)
{
    HRESULT     hr = E_POINTER;
    if(pbstrName)
    {
        CComBSTR    bstrAppName = _T("");
        bstrAppName.LoadString( IDS_PLUGIN_NAME );
        *pbstrName = bstrAppName.Detach();
        hr = *pbstrName? S_OK : E_POINTER;
    }
    return hr;
}

//***************************************************************************
// GetScriptableObject()
// There is no scriptable object in this application
//***************************************************************************
HRESULT NAudio::Internal::CRemoteHost::GetScriptableObject(BSTR * pbstrName, IDispatch ** ppDispatch)
{
    if(pbstrName)
    {
        *pbstrName = NULL;
    }
    if(ppDispatch)
    {
        *ppDispatch = NULL;
    }
    return E_NOTIMPL;
}

//***************************************************************************
// GetCustomUIMode()
// When UI mode of the player OCX is set to custom, this function is called
// to give the skin file path that will be loaded to the player OCX.
//
//***************************************************************************
HRESULT NAudio::Internal::CRemoteHost::GetCustomUIMode(BSTR * pbstrFile)
{
    return E_NOTIMPL; // Dont want ANY ui, no custom one in particular.
}
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 5

Expert Comment

by:Daij-Djan
ID: 9837186
The container is the relevant one IMO
0
 

Author Comment

by:imti_lak
ID: 9838872
thanks for the sample code, But From which class the ccontainer and nauido class are subclassed.

And will this code work without the support of mfc libraries? and are all the interfaces
implemented in this code?


Please also show me the header files for both the classes?






0
 
LVL 48

Expert Comment

by:AlexFM
ID: 9841372
Use ATL or WTL.
0
 

Author Comment

by:imti_lak
ID: 9841557
can't i show an activex control using pure win32 without atl/wtl or mfc
0
 

Author Comment

by:imti_lak
ID: 9841558
can't i show an activex control using pure win32 without atl/wtl or mfc ?

0
 
LVL 5

Expert Comment

by:Daij-Djan
ID: 9842285
you can. see above
NAudio is only a namespace
0
 

Author Comment

by:imti_lak
ID: 9842946
Well but how do I integrate my dialog proceadure with this code?
can u suggest an answer
?
0
 
LVL 5

Expert Comment

by:Daij-Djan
ID: 9842969
Ok I'll pass. It _IS_ possible but complex. Try ATL (the above code even uses ATL too)
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9843848
What is your reason to avoid MFC?  All computers have the MFC DLLs so there is no overhead problem.

-- Dan
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
Before we dive into the marketing strategies involved with creating an effective homepage, it’s crucial that EE members know what a homepage is. In essence, a homepage is the introductory, or default page, of a website that typically highlights the …
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question