Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ConvertStringToBSTR link error

Status
Not open for further replies.

jihervas

Programmer
Joined
Feb 7, 2003
Messages
4
Location
ES
I am trying to link a MFC exe project in VC7 and I am having problem with the _variant_t object. The error I get is:

targets.obj : error LNK2019: unresolved external symbol "wchar_t * __stdcall _com_util::ConvertStringToBSTR(char const *)" (?ConvertStringToBSTR@_com_util@@YGPA_WPBD@Z) referenced in function "public: __thiscall _variant_t::_variant_t(char const *)" (??0_variant_t@@QAE@PBD@Z)

It seems that the problem is with the ConvertStringToBSTR function. I have tested a project with just the piece of code that appears in the MSDN help for the ConvertStringToBSTR and I get the same error. The code is:
char* lpszText = "Test";
printf("char * text: %s\n", lpszText);
BSTR bstrText = _com_util::ConvertStringToBSTR(lpszText);
wprintf(L"BSTR text: %s\n", bstrText);
SysFreeString(bstrText);

I have used the #include <comutil.h> and I have linked with the comsupp.lib library.
I have tested the same code with a Win32 project (no MFC) and it works fine, so the problem has something to do with MFC? How can I solve it?
Any help will be appreciate!!
Thanks in advance.

 
Well, it seems that I know where the problem was.
In order to link without error I have to set in Setting of the project in &quot;C/C++ -> Language -> Treat wchar_t as Built-In Type&quot; to &quot;No&quot; (originally it was: &quot;Yes(/Zc:wchar_t)&quot;.

(I am working with Visual Studio .NET)

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top