下面是main.cpp代码
// xx.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <cassert>
//#pragma comment(lib,"atl")
#import "f:\\mycode\\xx\\MOCPlayer.ocx" \
no_namespace // #import "f:\\mycode\\xx\\AuthCtrl.ocx" \
//  no_namespace  raw_interfaces_only \
// raw_native_types no_implementation named_guids
int main()
{
    CoInitialize(0) ; 
    {
        _DMOCPlayerPtr pitd = 0;       HRESULT hr = pitd.CreateInstance(__uuidof(MOCPlayer));
        assert(SUCCEEDED(hr));

        unsigned short* version = 0;

        assert(SUCCEEDED(hr)) ;

pitd->GetVersion() ;        std::cout << "iTunes versi
需要提供ocx文件的话请加我QQ:304146959  ,注明来意即可
另外有生成的tlh文件和tli文件如下:
tlh文件:// Created by Microsoft (R) C/C++ Compiler Version 12.00.8447.0 (355ecce2).
//
// f:\mycode\xx\debug\MOCPlayer.tlh
//
// C++ source equivalent of Win32 type library f:\\mycode\\xx\\MOCPlayer.ocx
// compiler-generated file created 09/06/10 at 17:38:17 - DO NOT EDIT!#pragma once
#pragma pack(push, 8)#include <comdef.h>//
// Forward references and typedefs
//struct __declspec(uuid("d75d393f-c714-4dda-b160-2af90008293f"))
/* dispinterface */ _DMOCPlayer;
struct __declspec(uuid("a472cb14-0213-4e30-8c2b-67a338754f36"))
/* dispinterface */ _DMOCPlayerEvents;
struct /* coclass */ MOCPlayer;
//
// Smart pointer typedef declarations
//_COM_SMARTPTR_TYPEDEF(_DMOCPlayer, __uuidof(IDispatch));
_COM_SMARTPTR_TYPEDEF(_DMOCPlayerEvents, __uuidof(IDispatch));
//
// Type library items
//
struct __declspec(uuid("d75d393f-c714-4dda-b160-2af90008293f"))
_DMOCPlayer : IDispatch
{
    //
    // Wrapper methods for error-handling
    //    // Methods:
    long OpenStream (
        _bstr_t sURL,
        _bstr_t sGUID,
        _bstr_t sGUKEY,
        _bstr_t sGUName );
    long GetDivMode ( );
    long SetDivMode (
        long nNewValue );
    long GetCurSelectWindow ( );
    long SetCurSelectWindow (
        long nNewValue );
    long GetFirstIdleWindow ( );
    long GetFullScreen ( );
    long SetFullScreen (
        long nNewValue );
    long Play ( );
    long Pause ( );
    long Stop ( );
    long SetPlayRate (
        long nNewValue );
    long GetTimeShiftRange (
        double * start,
        double * end,
        double * current );
    long GoTimeShiftStart ( );
    long GoTimeShiftEnd ( );
    double GetTotalTime ( );
    double GetPosition ( );
    long SetPosition (
        double dNewValue );
    long SetToolBarMode (
        long nNewValue );
    long GetToolBarMode ( );
    long SetContextMenuMode (
        long nNewValue );
    long GetContextMenuMode ( );
    long OpenRecord (
        _bstr_t sURL,
        _bstr_t sRange );
    long CapPic (
        long nPrompt,
        _bstr_t sFileName );
    long SetProxy (
        long nMode,
        long nType,
        _bstr_t sIP,
        long nPort,
        _bstr_t sUser,
        _bstr_t sPass );
    _bstr_t GetVersion ( );
    long SetVersion (
        _bstr_t sNewVersion,
        long nReplace );
    long Close ( );
    long CloseAll ( );
    _bstr_t GetGUID ( );
    _bstr_t GetGUKey ( );
    _bstr_t GetGUName ( );
    long HitTest (
        long x,
        long y,
        long * windowIndex );
    long SetLoginParam (
        _bstr_t sServerIP,
        long nServerPort,
        _bstr_t sUser );
    long OpenGUStream (
        _bstr_t sGUID,
        long nStreamID );
    long OpenRecordTask (
        long nTaskID,
        _bstr_t sStartTime,
        _bstr_t sEndTime );
    long SetPTZParam (
        _bstr_t sServerIP,
        long nServerPort,
        _bstr_t sUser );
    long SendPTZControl (
        _bstr_t sGUID,
        long nPTZType );
    long SetQos (
        long nEnable,
        long nBufferTime );
    long VolumeSet (
        _bstr_t sCmd,
        long nParam );
    long GetPlayerStatus (
        long * nStatus,
        long * nRate );
    long GetStatus (
        _bstr_t sCmd,
        long nParam );
    long SetTransportMode (
        long nMode );
    long Invalidate ( );
    long OpenXmlRecordTask (
        _bstr_t sXmlFile,
        _bstr_t sStartTime,
        _bstr_t sEndTime );
    long SetPluginMode (
        long nMode );
    long OpenPURecord (
        _bstr_t sTaskID,
        _bstr_t sGUID );
    long Login (
        _bstr_t sServerIP,
        long nPort,
        _bstr_t sUser,
        _bstr_t sPassword );
    long LogOut ( );
    long SendPTZControlTCP (
        _bstr_t sGUID,
        long nPTZType );
    long StartTalk (
        _bstr_t sGUID );
    long StopTalk ( );
    long StartBroadcast (
        _bstr_t sGUList );
    long StopBroadcast ( );
    long OpenStreamEx (
        _bstr_t sURL,
        long nMode );
    long OpenGUStreamEx (
        _bstr_t sGUID,
        long nStreamID,
        long nLinkType );
    long OpenRecordTaskEx (
        _bstr_t sFileID,
        _bstr_t sGUID,
        _bstr_t sStartTime,
        _bstr_t sEndTime );
    long OpenPURecordEx (
        _bstr_t sTaskID,
        _bstr_t sGUID );
    long OpenRecordFile (
        _bstr_t sFilePath );
    long FastSlowPlay (
        long nNewValue );
    _bstr_t GetTimeShiftRangeEx ( );
    long SetTimeShiftPosition (
        _bstr_t sPos );
    long SetDefaultRecordPath (
        _bstr_t sRecPath );
    _bstr_t GetDefaultRecordPath ( );
    long SetDefaultSnapPath (
        _bstr_t sSnapPath );
    _bstr_t GetDefaultSnapPath ( );
    _bstr_t CapPicEx (
        long nPrompt,
        _bstr_t sFileName );
    long StartLocalRecord (
        _bstr_t sGUID,
        long nStreamID );
    long StopLocalRecord (
        _bstr_t sGUID,
        long nStreamID );
    long SetPageCount (
        long nPageCount );
    long QueryRecordTask (
        _bstr_t sGUID,
        _bstr_t sType,
        _bstr_t sStartTime,
        _bstr_t sEndTime,
        long nPageIndex );
    long QueryRecordPU (
        _bstr_t sGUID,
        _bstr_t sType,
        _bstr_t sStartTime,
        _bstr_t sEndTime,
        long nPageIndex );
    long QueryRecordFile (
        _bstr_t sGUID,
        _bstr_t sStartTime,
        _bstr_t sEndTime,
        long nPageIndex );
    long ShowContextMenuItem (
        long nFirstID,
        long nSecondID,
        long nShow );
    long GetPageCount ( );
    long GetDeviceList ( );
    long RefreshDeviceList ( );
    long StartNetRecord (
        _bstr_t sGUID,
        long nStreamID,
        long nDuration );
    long StopNetRecord (
        _bstr_t sGUID,
        long nStreamID );
    long StartPURecord (
        _bstr_t sGUID,
        long nStreamID,
        long nDuration );
    long StopPURecord (
        _bstr_t sGUID,
        long nStreamID );
    long SetPTZRotateStepValue (
        long value );
    long GetPTZRotateStepValue ( );
    long SetPTZStepValue (
        long value );
    long GetPTZStepValue ( );
    long ChangePassword (
        _bstr_t sOldPsw,
        _bstr_t sNewPsw );
    long GetGUStatus (
        _bstr_t sGUID,
        _bstr_t sCmd );
    long OpenIgmpStream (
        _bstr_t sIgmpURL,
        VARIANT_BOOL bSupTimeshift,
        _bstr_t sSDP,
        _bstr_t sTimeshiftURL );
    HRESULT AboutBox ( );
};struct __declspec(uuid("a472cb14-0213-4e30-8c2b-67a338754f36"))
_DMOCPlayerEvents : IDispatch
{
    //
    // Wrapper methods for error-handling
    //    // Methods:
    HRESULT DivModeChange (
        long nDivMode );
    HRESULT PUStatusChange (
        long nType,
        _bstr_t sChange );
    HRESULT DeviceListReturn (
        long nStatusCode,
        _bstr_t sDeviceList );
    HRESULT PTZControlReturn (
        long nStatusCode,
        _bstr_t sGUID,
        long nPTZType );
    HRESULT QueryRecordReturn (
        long nQueryType,
        _bstr_t sGUID,
        _bstr_t sQueryResult );
};struct __declspec(uuid("ab70953c-cd32-4ce0-bea8-07365e319c2b"))
MOCPlayer;
    // [ default ] dispinterface _DMOCPlayer
    // [ default, source ] dispinterface _DMOCPlayerEvents//
// Wrapper method implementations
//#include "f:\mycode\xx\debug\MOCPlayer.tli"#pragma pack(pop)

解决方案 »

  1.   

    tli文件内容太长发不了就不发了,本贴我随时关注,各位高手也可以留下邮箱我发过来
      

  2.   

    前面没发完整,main.cpp的代码完整为// xx.cpp : Defines the entry point for the console application.
    //
    //#include "stdafx.h"
    #include <iostream>
    #include <windows.h>
    #include <cassert>//#pragma comment(lib,"atl")
    #import "C:\\Program Files\\视频播放器插件\\MOCPlayer.ocx" \
    no_namespace // #import "f:\\mycode\\xx\\AuthCtrl.ocx" \
    //  no_namespace  raw_interfaces_only \
    // raw_native_types no_implementation named_guidsint main()
    {
        CoInitialize(0) ; 
        {
            _DMOCPlayerPtr pitd = 0;       HRESULT hr = pitd.CreateInstance(__uuidof(MOCPlayer));
            assert(SUCCEEDED(hr));

            unsigned short* version = 0;

            assert(SUCCEEDED(hr)) ;

    pitd->GetVersion() ;        std::cout << "iTunes version is " 
                << std::hex                
                << std::showbase 
                << version 
                << '\n' ;  
    pitd->Release();
        }  
        CoUninitialize() ;
    return 0;
    }其中 pitd->GetVersion() ;函数会出错,这是控件提供的函数,不使用则通过编译
      

  3.   

    到底出了什么错? 你catch COM exception看看
    什么叫不使用则通过编译?难道是编译错误?
      

  4.   

    简单点说就是编译通过,运行出错,程序abnormal program termination,崩溃掉了
      

  5.   

    简单点说就是编译通过,运行出错,程序abnormal program termination,崩溃掉了