Solved

Using activex controls in win32 (non mfc) dll

Posted on 2003-11-27
12
771 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
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…

726 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