在網上看到一篇get flash version 的代碼覺得不錯
class CFlashocx?
{
public:
?CFlashocx();
?virtual ~CFlashocx();
?
?CString getVersion();
};
#include "stdafx.h"
#include "flashocx.h"
#include "comdef.h"
#include <atlbase.h>
#define COMR_CHECK(x) \
do \
{? \
if( FAILED(x) ) \
_com_issue_error((x)); \
} while (0) \
#ifdef _WIN32
#define LOADLIBRARY_FAILED(x) (x == 0)
#else
#define LOADLIBRARY_FAILED(x) (x <= HINSTANCE_ERROR)
#endif
STDAPI DllRegisterServer(void) ;
typedef HRESULT (STDAPICALLTYPE *CTLREGPROC)();
CFlashocx::CFlashocx()
{
}
CFlashocx::~CFlashocx()
{
}
CString CFlashocx::getVersion()
{
?USES_CONVERSION;
?CString strVersion;
?try
?{
??CoInitialize(NULL);?
??wchar_t progid[] = L"ShockwaveFlash.ShockwaveFlash";
??CLSID clsid;
??COMR_CHECK(::CLSIDFromProgID(progid, &clsid));
??
??// get the IDispatch Interface
??IDispatch* pIDispatch = NULL;
??COMR_CHECK(::CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_IDispatch, (void**)&pIDispatch));
??BSTR szMember = OLESTR("FlashVersion");
??DISPID dispid;
??
??COMR_CHECK(pIDispatch->GetIDsOfNames(IID_NULL, &szMember, 1, LOCALE_USER_DEFAULT, &dispid));
??DISPPARAMS dispParams = {NULL,?? NULL,?? 0,?? 0};? ;
??VARIANT??? varResult;
?
??COMR_CHECK(pIDispatch->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD,
???????? &dispParams, &varResult, NULL, NULL));
??strVersion.Format(_T("%x"), varResult.intVal);
??CString strDevVersion;
???????
??strDevVersion = strVersion.Left(strVersion.GetLength() - 4);
??long nVersion = strtol(T2A(strDevVersion), NULL, 16);
??????? strVersion.Format(_T("%ld"), nVersion);
??strVersion = strVersion + _T("0000");
??pIDispatch->Release();
??CoUninitialize();
?}
?catch (_com_error& e)
?{
??e;
??strVersion = _T("0000");
?}
?return strVersion;
}