#include <comutil.h> cause errors

0 votes
asked Dec 7, 2010 by cynede

VS 2010 C++ CLR Library project, errors on adding comutil.h library

> 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

needed for

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;
        }*/

how can I fix it ?

3 Answers

0 votes
answered Dec 7, 2010 by steve-o

Add the requisite import library as per the documentation, likely Oleaut32.lib

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

edit: I'm assuming the Compiler COM Support library subsumes this and Alex's answer would be the preferred library.

0 votes
answered Dec 7, 2010 by alex-f

According to MSDN, _bstr_t requires comsuppw.lib. Add this library to the linker dependencies list.

0 votes
answered Dec 24, 2012 by zhen-ma

try to include comdef.h, don't include comutil.h

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...