unsignend short* 转换为BSTR时候错误了

liuzu2016 2012-09-25 05:15:44

#ifndef String
typedef unsigned short *String;
#endif


_com_util::ConvertBSTRToString // 这里错误



BOOL CDictionary::LoadLibrary(String filename)
{
char *pFileName = _com_util::ConvertBSTRToString(filename); //error
FILE *fp;
if( (fp = fopen( pFileName, "rt" )) == NULL ) {
printf("Open dictionary file : %s failed.\n", pFileName);
delete pFileName;
return FALSE;
}



namespace _com_util {

// Convert BSTR to char *
//
char* __stdcall ConvertBSTRToString(BSTR pSrc) ;
}


也就是说,原作者的意图是:将 unsigned short* 转化为BSTR时候发生错了。

我们去类BSTR中看看有没有构造函数啊


class _bstr_t {
public:
// Constructors
//
_bstr_t() throw();
_bstr_t(const _bstr_t& s) throw();
_bstr_t(const char* s) ;
_bstr_t(const wchar_t* s) ;
_bstr_t(const _variant_t& var) ;
_bstr_t(BSTR bstr, bool fCopy) ;

// Destructor
//
~_bstr_t() throw();


// Extractors
//
operator const wchar_t*() const throw();
operator wchar_t*() const throw();
operator const char*() const ;
operator char*() const ;


// Low-level helper functions
//
BSTR copy(bool fCopy = true) const ;
unsigned int length() const throw();

// Binary string assign
//
void Assign(BSTR s) ;

// Get the physical BSTR
//
BSTR& GetBSTR() ;
BSTR* GetAddress() ;

// Attach to the internal BSTR w/o copying
//
void Attach(BSTR s) ;

// Detach the internal BSTR
//
BSTR Detach() throw();

private:
// Referenced counted wrapper
//
class Data_t {
public:
// Constructors
//
Data_t(const char* s) ;
Data_t(const wchar_t* s) ;
Data_t(BSTR bstr, bool fCopy) ;
Data_t(const _bstr_t& s1, const _bstr_t& s2) ;

// Reference counting routines
//
unsigned long AddRef() throw();
unsigned long Release() throw();
unsigned long RefCount() const throw();

// Extractors
//
operator const wchar_t*() const throw();
operator const char*() const ;

// Low-level helper functions
//
const wchar_t* GetWString() const throw();
wchar_t*& GetWString() throw();
const char* GetString() const ;

BSTR Copy() const ;
void Assign(BSTR s) ;
void Attach(BSTR s) throw();
unsigned int Length() const throw();
int Compare(const Data_t& str) const throw();

// Exception agnostic wrapper for new
//
void* operator new(size_t sz);

private:
BSTR m_wstr;
mutable char* m_str;
unsigned long m_RefCount;

// Never allow default construction
//
Data_t() throw();

// Never allow copy
//
Data_t(const Data_t& s) throw();

// Prevent deletes from outside. Release() must be used.
//
~Data_t() throw();

void _Free() throw();
};

private:
// Reference counted representation
//
Data_t* m_Data;

private:
// Low-level utilities
//
void _AddRef() throw();
void _Free() throw();
int _Compare(const _bstr_t& str) const throw();
};

//////////////////////////////////////////////////////////////////////////////


似乎没啊, 当时作者写书的时候,在vc6下写,现在 的编译器已经无法编译了

...全文
111 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lxw_it 2012-09-28
  • 打赏
  • 举报
回复
BSTR的数据类型是unsigned short,但不是说unsigned short就是BSTR。
BSTR前面几个字节有字符串的信息。

你先用SysAllocString()转一下试试。
stjay 2012-09-25
  • 打赏
  • 举报
回复
现在的编译器严谨多了
需要显式加强制转换
_com_util::ConvertBSTRToString((wchar_t*)filename)
liuzu2016 2012-09-25
  • 打赏
  • 举报
回复
你想说什么

参数类型是BSTR!!!


构造函数没有 unsigned short*

lxw_it 2012-09-25
  • 打赏
  • 举报
回复
BOOL CDictionary::LoadLibrary(String filename)

char *pFileName = _com_util::ConvertBSTRToString(filename); //error


filename是String
ConvertBSTRToString :BSTR -> string

你再好好看看这两行。

16,465

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧