Article View: borland.public.cppbuilder.nativeapi
Article #10258Re: Stopping DVD/Audio CD autoplay
From: Simon Macneall
Date: Tue, 11 May 2004 00:37
Date: Tue, 11 May 2004 00:37
216 lines
5958 bytes
5958 bytes
"Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> wrote in
news:40a01e60$1@newsgroups.borland.com:
>
> Can you please show your actual code?
>
>
> Gambit
>
>
>
Sure, this is all taken from
<http://msdn.microsoft.com/msdnmag/issues/01/11/autoplay/default.aspx>
Enjoy,
Simon
AutoPlayInterceptor.h
#ifndef AUTO_PLAY_INTERCEPTOR_H
#define AUTO_PLAY_INTERCEPTOR_H
#include <thirdparty/DirectXBaseClasses.h>
#include "shobjidl.h"
#include <initguid.h>
class CAutoPlayInterceptor : public IQueryCancelAutoPlay
{
protected:
public:
STDMETHODIMP QueryInterface(REFIID riid, void** ppv);
STDMETHODIMP_(ULONG) AddRef();
STDMETHODIMP_(ULONG) Release();
STDMETHODIMP AllowAutoPlay(LPCWSTR pszPath, DWORD dwContentType, LPCWSTR
pszLabel, DWORD dwSerialNumber);
HRESULT Init(DWORD dwContentType);
CAutoPlayInterceptor();
~CAutoPlayInterceptor(){};
private:
ULONG _cRef;
DWORD _dwContentType;
};
#endif // AUTO_PLAY_INTERCEPTOR_H
AutoPlayInterceptoruids.h
const static CLSID g_clsidAutoPlayInterceptor =
{ 0x0914a446, 0xe6fa, 0x42a4,
{ 0x9a, 0x8a, 0x7d, 0x9b, 0xdd, 0x87, 0xf0, 0x17 }};
struct __declspec(
uuid("{0914A446-E6FA-42a4-9A8A-7D9BDD87F017}")) CLSID_AutoPlayInterceptor;
DEFINE_GUID(CLSID_AutoPlayInterceptor,
0x0914A446, 0xE6FA, 0x42a4, 0x9A, 0x8A, 0x7D, 0x9B, 0xDD, 0x87, 0xF0,
0x17);
struct __declspec(
uuid("{DDEFE873-6997-4e68-BE26-39B633ADBE12}")) CLSID_QueryCancelAutoPlay;
DEFINE_GUID(CLSID_QueryCancelAutoPlay,
0xDDEFE873, 0x6997, 0x4e68, 0xBE, 0x26, 0x39, 0xB6, 0x33, 0xAD, 0xBE,
0x12);
struct __declspec(
uuid("{DDEFE873-6997-4e68-BE26-39B633ADBE12}")) IID_IQueryCancelAutoPlay;
DEFINE_GUID(IID_IQueryCancelAutoPlay,
0xDDEFE873, 0x6997, 0x4e68, 0xBE, 0x26, 0x39, 0xB6, 0x33, 0xAD, 0xBE,
0x12);
AutoPlayInterceptor.cpp
#include "AutoPlayInterceptor.h"
#include "AutoPlayIntercepteruids.h"
CAutoPlayInterceptor::CAutoPlayInterceptor() :
_cRef(1)
{
}
HRESULT CAutoPlayInterceptor::Init(DWORD dwContentType)
{
_dwContentType = dwContentType;
return S_OK;
}
STDMETHODIMP CAutoPlayInterceptor::AllowAutoPlay(LPCWSTR pszPath, DWORD
dwContentType, LPCWSTR pszLabel, DWORD dwSerialNumber)
{
HRESULT hr = S_OK;
if (dwContentType & _dwContentType)
{
hr = S_FALSE;
}
return hr;
}
STDMETHODIMP CAutoPlayInterceptor::QueryInterface(REFIID riid, void** ppv)
{
IUnknown* punk = NULL;
HRESULT hr = S_OK;
if (IID_IUnknown == riid)
{
punk = static_cast<IUnknown*>(this);
punk->AddRef();
}
else
{
if (IID_IQueryCancelAutoPlay == riid)
{
punk = static_cast<IQueryCancelAutoPlay*>(this);
punk->AddRef();
}
else
{
hr = E_NOINTERFACE;
}
}
*ppv = punk;
return hr;
}
STDMETHODIMP_(ULONG) CAutoPlayInterceptor::AddRef()
{
return ::InterlockedIncrement((LONG*)&_cRef);
}
STDMETHODIMP_(ULONG) CAutoPlayInterceptor::Release()
{
ULONG cRef = ::InterlockedDecrement((LONG*)&_cRef);
if (!cRef)
{
delete this;
}
return cRef;
}
Add
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer
\AutoplayHandlers\CancelAutoplay\CLSID\0914A446-E6FA-42A4-9A8A-7D9BDD87F017
as a string key with no value
In the application, Call RegisterAutoPlay to activate, and
UnRegisterAutoplay to disable
void __fastcall TDVDForm::UnRegisterAutoplay()
{
IRunningObjectTable *prot;
if (SUCCEEDED(GetRunningObjectTable(0, &prot)))
{
prot->Revoke(_dwRegisterROT);
prot->Release();
}
}
void __fastcall TDVDForm::RegisterAutoplay()
{
DWORD dwContentType = ARCONTENT_DVDMOVIE;
IMoniker* pMoniker;
HRESULT hr = CreateClassMoniker(g_clsidAutoPlayInterceptor, &pMoniker);
if (SUCCEEDED(hr))
{
IRunningObjectTable* prot;
hr = GetRunningObjectTable(0, &prot);
if (SUCCEEDED(hr))
{
CAutoPlayInterceptor* pQCA = new CAutoPlayInterceptor();
if (pQCA)
{
hr = pQCA->Init(dwContentType);
if (SUCCEEDED(hr))
{
IUnknown* punk;
hr = pQCA->QueryInterface(IID_IUnknown, (void**)&punk);
if (SUCCEEDED(hr))
{
// register
hr = prot->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE,
punk, pMoniker, &_dwRegisterROT);
if (SUCCEEDED(hr))
{
dprintf("Registered!!!");
}
punk->Release();
}
}
pQCA->Release();
}
else
{
hr = E_OUTOFMEMORY;
}
prot->Release();
}
pMoniker->Release();
}
}
Technical Details
Message-ID:
<Xns94E65829AE7D4macnealliinetnetau@207.105.83.66>Path:
arc1-ca.pugleaf.net!controlnews3.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<Xns94E15253CC42Fmacnealliinetnetau@207.105.83.66> <409984a1$1@newsgroups.borland.com> <Xns94E160383D857macnealliinetnetau@207.105.83.66> <4099b0ae$1@newsgroups.borland.com> <Xns94E24E78DCBC3macnealliinetnetau@207.105.83.66> <409ad659$1@newsgroups.borland.com> <Xns94E64A765FD08macnealliinetnetau@207.105.83.66> <40a01e60$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,dcdee2de1c7c274c X-Google-Attributes: gid10cc67,public Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Stopping DVD/Audio CD autoplay From: Simon Macneall <macneall-at-iinet.net.au> References: <Xns94E15253CC42Fmacnealliinetnetau@207.105.83.66> <409984a1$1@newsgroups.borland.com> <Xns94E160383D857macnealliinetnetau@207.105.83.66> <4099b0ae$1@newsgroups.borland.com> <Xns94E24E78DCBC3macnealliinetnetau@207.105.83.66> <409ad659$1@newsgroups.borland.com> <Xns94E64A765FD08macnealliinetnetau@207.105.83.66> <40a01e60$1@newsgroups.borland.com> Message-ID: <Xns94E65829AE7D4macnealliinetnetau@207.105.83.66> User-Agent: Xnews/5.04.25 NNTP-Posting-Host: 203.153.243.50 Date: 10 May 2004 17:37:24 -0700 X-Trace: newsgroups.borland.com 1084235844 203.153.243.50 (10 May 2004 17:37:24 -0700) Lines: 216 Path: arc1-ca.pugleaf.net!controlnews3.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail