• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 781
  • Last Modified:

Using activex controls in win32 (non mfc) dll

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
imti_lak
Asked:
imti_lak
1 Solution
 
Daij-DjanCommented:
U need to HOST the control in your own COM container. You need to implement various interfaces.
0
 
imti_lakAuthor Commented:
But how to host a control in my own container.

can u give any sample code
0
 
Daij-DjanCommented:
// 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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Daij-DjanCommented:
The container is the relevant one IMO
0
 
imti_lakAuthor Commented:
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
 
AlexFMCommented:
Use ATL or WTL.
0
 
imti_lakAuthor Commented:
can't i show an activex control using pure win32 without atl/wtl or mfc
0
 
imti_lakAuthor Commented:
can't i show an activex control using pure win32 without atl/wtl or mfc ?

0
 
Daij-DjanCommented:
you can. see above
NAudio is only a namespace
0
 
imti_lakAuthor Commented:
Well but how do I integrate my dialog proceadure with this code?
can u suggest an answer
?
0
 
Daij-DjanCommented:
Ok I'll pass. It _IS_ possible but complex. Try ATL (the above code even uses ATL too)
0
 
DanRollinsCommented:
What is your reason to avoid MFC?  All computers have the MFC DLLs so there is no overhead problem.

-- Dan
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now