怎样在ATL中声明自己的结构?
我在IDL中声明了自己的结构,可是编译的时候硬是说名称没有声明……郁闷!我用的是VC.NET,错误信息如下:
d:\files\com\mp3tool\mp3file.h(32): error MIDL2025 : syntax error : expecting a type specification near "MP3_INFO_IDV1"
IDL代码如下:
// Mp3File.h : CMp3File 的声明
#pragma once
#include "resource.h" // 主符号
#include <string>
using namespace std;
// Struct of Mp3 File infomation IDv1
typedef struct _MP3_INFO_IDV1
{
char Tag[3]; // IDv1标志,始终为“TAG”
char Title[30]; // 标题
char Artist[30]; // 艺术家
char Album[30]; // 专辑
char Year[4]; // 年代
char Comment[30]; // 注释
char Genre; // 风格
}MP3_INFO_IDV1;
// IMp3File
[
object,
uuid("2571A8A7-E284-4F88-A42C-A1AF74F8FDEE"),
dual, helpstring("IMp3File 接口"),
pointer_default(unique)
]
__interface IMp3File : IDispatch
{
[id(1), helpstring("方法Open")] HRESULT Open([in] LPCTSTR lpszFilename);
[id(2), helpstring("方法Close")] HRESULT Close(void);
[id(3), helpstring("方法GetMp3Info")] HRESULT GetMp3Info([out] MP3_INFO_IDV1* info);
[id(4), helpstring("方法SetMp3Info")] HRESULT SetMp3Info([in] MP3_INFO_IDV1* info);
};
// CMp3File
[
coclass,
threading("apartment"),
vi_progid("Mp3Tool.Mp3File"),
progid("Mp3Tool.Mp3File.1"),
version(1.0),
uuid("329108FE-25AB-437E-A270-F78613E317DC"),
helpstring("Mp3File Class")
]
class ATL_NO_VTABLE CMp3File :
public IMp3File
{
public:
CMp3File()
{
}
DECLARE_PROTECT_FINAL_CONSTRUCT()
HRESULT FinalConstruct()
{
return S_OK;
}
void FinalRelease()
{
}
public:
STDMETHOD(Open)(LPCTSTR lpszFilename);
STDMETHOD(Close)(void);
STDMETHOD(GetMp3Info)(MP3_INFO_IDV1* info);
STDMETHOD(SetMp3Info)(MP3_INFO_IDV1* info);
protected:
// // IDv1 Information
MP3_INFO_IDV1 m_Info1;
// // Full path name
string m_strFileName;
// // Opened Mp3 File handle
HANDLE m_hFile;
};