Solved

Using activex controls in win32 (non mfc) dll

Posted on 2003-11-27
12
759 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
Comment Utility
U need to HOST the control in your own COM container. You need to implement various interfaces.
0
 

Author Comment

by:imti_lak
Comment Utility
But how to host a control in my own container.

can u give any sample code
0
 
LVL 5

Expert Comment

by:Daij-Djan
Comment Utility
// 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
 
LVL 5

Expert Comment

by:Daij-Djan
Comment Utility
The container is the relevant one IMO
0
 

Author Comment

by:imti_lak
Comment Utility
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
Comment Utility
Use ATL or WTL.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

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

Author Comment

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

0
 
LVL 5

Expert Comment

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

Author Comment

by:imti_lak
Comment Utility
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
Comment Utility
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
Comment Utility
What is your reason to avoid MFC?  All computers have the MFC DLLs so there is no overhead problem.

-- Dan
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now