#include <comutil.h>导致错误</comutil.h>

时间:2010-12-07 09:07:45

标签: c++ clr

VS 2010 C ++ CLR Library项目,添加comutil.h库时出错

> Error 20  error LNK2001: unresolved
> external symbol "extern "C" long
> __stdcall VariantCopy(struct tagVARIANT *,struct tagVARIANT const
> *)" (?VariantCopy@@$$J18YGJPAUtagVARIANT@@PBU1@@Z)    D:\Projects\AL\Service\ncFlow\ncOPClient.NET\Stdafx.obj ncOPClient.NET
> Error 18  error LNK2001: unresolved
> external symbol "extern "C" void
> __stdcall VariantInit(struct tagVARIANT *)"
> (?VariantInit@@$$J14YGXPAUtagVARIANT@@@Z) D:\Projects\AL\Service\ncFlow\ncOPClient.NET\Stdafx.obj ncOPClient.NET
> Error 13  error LNK2001: unresolved
> external symbol "void __stdcall
> _com_issue_error(long)" (?_com_issue_error@@$$FYGXJ@Z)    D:\Projects\AL\Service\ncFlow\ncOPClient.NET\Stdafx.obj ncOPClient.NET
> Error 10  error LNK2028: unresolved
> token (0A000376) "void __stdcall
> _com_issue_error(long)" (?_com_issue_error@@$$FYGXJ@Z)
> referenced in function "void __cdecl
> _com_util::CheckError(long)" (?CheckError@_com_util@@$$FYAXJ@Z)   D:\Projects\AL\Service\ncFlow\ncOPClient.NET\Stdafx.obj ncOPClient.NET
> Error 4   error LNK2028: unresolved
> token (0A0003BC) "extern "C" void
> __stdcall VariantInit(struct tagVARIANT *)"
> (?VariantInit@@$$J14YGXPAUtagVARIANT@@@Z)
> referenced in function "public:
> __thiscall _variant_t::_variant_t(class _variant_t const &)" (??0_variant_t@@$$FQAE@ABV0@@Z)  D:\Projects\AL\Service\ncFlow\ncOPClient.NET\Stdafx.obj ncOPClient.NET
> Error 2   error LNK2028: unresolved
> token (0A0003D1) "extern "C" long
> __stdcall VariantCopy(struct tagVARIANT *,struct tagVARIANT const
> *)" (?VariantCopy@@$$J18YGJPAUtagVARIANT@@PBU1@@Z)
> referenced in function "public:
> __thiscall _variant_t::_variant_t(class _variant_t const &)" (??0_variant_t@@$$FQAE@ABV0@@Z)  D:\Projects\AL\Service\ncFlow\ncOPClient.NET\Stdafx.obj ncOPClient.NET

需要

private:
        std::string from_variant(VARIANT& vt)
        {
            _bstr_t bs(vt);
            return std::string(static_cast<const char*>(bs));
        }
        /*
        void to_variant(const std::string& str, VARIANT& vt)
        {
            _bstr_t bs(str.c_str());
            reinterpret_cast<_variant_t&>(vt) = bs;
        }*/

我该如何解决?

3 个答案:

答案 0 :(得分:39)

尝试包含comdef.h,不要包含comutil.h

答案 1 :(得分:22)

根据MSDN,_bstr_t需要 comsuppw.lib 。将此库添加到链接器依赖项列表。

答案 2 :(得分:2)

根据文档添加必需的导入库,可能是Oleaut32.lib

http://msdn.microsoft.com/en-us/library/ms221236.aspx

编辑:我假设Compiler COM Support库包含了这个,而Alex的答案将是首选的库。