VC++ 6.0的OLE/COM Object Viewer 问题以及IDL文件使用方法

wxixi 2008-04-14 10:40:32
我是一个COM组件的初学者,用Matlab7.1作了一个COM组件,从VC++ 6.0的OLE/COM Object Viewer中可以找到该组件,但是从ITypeLib Viewer对话框只能得到IDL文件,无法得到h文件和c文件。看了好几本参考书,都讲可以保存得到h文件和c文件,疑惑了!
另外,如果只能得到IDL文件,请高手指点使用方法,本人采用#impot "***.IDL",总提示找不到文件。
高分求指点。
...全文
1054 10 打赏 收藏 举报
写回复
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
xq19880825 2012-02-20
  • 打赏
  • 举报
回复
你好,请问:关于d:\debug\testcom2_1_0.tlh(49) : error C2146: syntax error : missing ';' before identifier 'MWFlags'这种错误你最后是怎么解决的啊,我现在也碰到了,已经折腾两天了。。。
wxixi 2008-04-26
  • 打赏
  • 举报
回复
虽然没有完全解决。但可以结题了。
  • 打赏
  • 举报
回复
这就是你dll库的问题了,并没有这个接口.
你看看IMWFlags这个接口定义在那个dll文件里面.
wxixi 2008-04-15
  • 打赏
  • 举报
回复
使用 no_namespace以后,仍然一样.
tlh文件如下:
#import "Testcom2_1_0.dll" no_namespace

// Created by Microsoft (R) C/C++ Compiler Version 12.00.9782.0 (a06899cb).
//
// d:\debug\Testcom2_1_0.tlh
//
// C++ source equivalent of Win32 type library Testcom2_1_0.dll
// compiler-generated file created 04/15/08 at 22:10:07 - DO NOT EDIT!

//
// Cross-referenced type libraries:
//
// #import "C:\MATLAB71\bin\win32\mwcomutil.dll"
//

#pragma once
#pragma pack(push, 8)

#include <comdef.h>

//
// Forward references and typedefs
//

struct /* coclass */ Testcom2class;
struct __declspec(uuid("4d9ca593-28b9-4762-9a48-7d0aa14c2530"))
/* dual interface */ ITestcom2class;

//
// Smart pointer typedef declarations
//

_COM_SMARTPTR_TYPEDEF(ITestcom2class, __uuidof(ITestcom2class));

//
// Type library items
//

struct __declspec(uuid("b99ca754-0911-4c23-a6fa-d83588934625"))
Testcom2class;
// [ default ] interface ITestcom2class

struct __declspec(uuid("4d9ca593-28b9-4762-9a48-7d0aa14c2530"))
ITestcom2class : IDispatch
{
//
// Property data
//

__declspec(property(get=GetMWFlags,put=PutMWFlags))
IMWFlagsPtr MWFlags;

//
// Wrapper methods for error-handling
//

IMWFlagsPtr GetMWFlags ( );
void PutMWFlags (
struct IMWFlags * ppvFlags );
HRESULT adddoubles (
long nargout,
VARIANT * z,
const _variant_t & x,
const _variant_t & y );
HRESULT sum_sub (
long nargout,
VARIANT * sum,
VARIANT * sub,
const _variant_t & x,
const _variant_t & y );

//
// Raw methods provided by interface
//

virtual HRESULT __stdcall get_MWFlags (
struct IMWFlags * * ppvFlags ) = 0;
virtual HRESULT __stdcall put_MWFlags (
struct IMWFlags * ppvFlags ) = 0;
virtual HRESULT __stdcall raw_adddoubles (
long nargout,
VARIANT * z,
VARIANT x,
VARIANT y ) = 0;
virtual HRESULT __stdcall raw_sum_sub (
long nargout,
VARIANT * sum,
VARIANT * sub,
VARIANT x,
VARIANT y ) = 0;
};

//
// Wrapper method implementations
//

#include "d:\debug\Testcom2_1_0.tli"

#pragma pack(pop)




错误信息:
d:\debug\testcom2_1_0.tlh(49) : error C2146: syntax error : missing ';' before identifier 'MWFlags'
d:\debug\testcom2_1_0.tlh(49) : error C2501: 'IMWFlagsPtr' : missing storage-class or type specifiers
d:\debug\testcom2_1_0.tlh(49) : error C2501: 'MWFlags' : missing storage-class or type specifiers
d:\debug\testcom2_1_0.tlh(55) : error C2146: syntax error : missing ';' before identifier 'GetMWFlags'
d:\debug\testcom2_1_0.tlh(55) : error C2501: 'IMWFlagsPtr' : missing storage-class or type specifiers
d:\debug\testcom2_1_0.tli(14) : error C2143: syntax error : missing ';' before 'tag::id'
d:\debug\testcom2_1_0.tli(14) : error C2433: 'IMWFlagsPtr' : 'inline' not permitted on data declarations
d:\debug\testcom2_1_0.tli(14) : error C2501: 'IMWFlagsPtr' : missing storage-class or type specifiers
d:\debug\testcom2_1_0.tli(14) : fatal error C1004: unexpected end of file found

mLee79 2008-04-15
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 akirya 的回复:]
默认那些类型在名字空间里面的。

怀疑你都没打开tlh文件看看。
[/Quote]

#import "dllname.dll" no_namespace
这样没有名字空间 ...

  • 打赏
  • 举报
回复
默认那些类型在名字空间里面的。

怀疑你都没打开tlh文件看看。
wxixi 2008-04-14
  • 打赏
  • 举报
回复
#import "dllname.dll"
生成了一个tlh文件,但是编译除了问题:
Compiling resources...
Compiling...
StdAfx.cpp
e:\test11\debug\testcom2_1_0.tlh(51) : error C2146: syntax error : missing ';' before identifier 'MWFlags'
e:\test11\debug\testcom2_1_0.tlh(51) : error C2501: 'IMWFlagsPtr' : missing storage-class or type specifiers
e:\test11\debug\testcom2_1_0.tlh(51) : error C2501: 'MWFlags' : missing storage-class or type specifiers
e:\test11\debug\testcom2_1_0.tlh(57) : error C2146: syntax error : missing ';' before identifier 'GetMWFlags'
e:\test11\debug\testcom2_1_0.tlh(57) : error C2501: 'IMWFlagsPtr' : missing storage-class or type specifiers
e:\test11\debug\testcom2_1_0.tli(14) : error C2143: syntax error : missing ';' before 'tag::id'
e:\test11\debug\testcom2_1_0.tli(14) : error C2433: 'IMWFlagsPtr' : 'inline' not permitted on data declarations
e:\test11\debug\testcom2_1_0.tli(14) : error C2501: 'IMWFlagsPtr' : missing storage-class or type specifiers
e:\test11\debug\testcom2_1_0.tli(14) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

51行的语句为: IMWFlagsPtr MWFlags;

看来dll中的类型没有导出来,请继续指点。
星羽 2008-04-14
  • 打赏
  • 举报
回复
up
effective_person 2008-04-14
  • 打赏
  • 举报
回复
COM 啊
到mfc、vc++中的com去问吧!估计这里知道的人不多!
  • 打赏
  • 举报
回复
不用idl文件就可以用啊
#import "dllname.dll"
会自动生成相关的文件.
直接就可以用.
发帖
C++ 语言

6.3w+

社区成员

C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
帖子事件
创建了帖子
2008-04-14 10:40
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下