Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using activex controls in win32 (non mfc) dll

Posted on 2003-11-27
12
Medium Priority
?
777 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 1500 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…

636 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