Stephen
Stephen

Reputation: 21

Convert LPSTR to BSTR using win32

I see how to do this using MFC, but what is the best way to convert a LPSTR to a BSTR in C++ using only the win32 libraries.

Upvotes: 2

Views: 2626

Answers (3)

Inno
Inno

Reputation: 2567

Don't know the concrete solution but I think this is gonna help you (especially part II):

The Complete Guide to C++ Strings, Part I - Win32 Character Encodings

The Complete Guide to C++ Strings, Part II - String Wrapper Classes

Upvotes: 1

JSBձոգչ
JSBձոգչ

Reputation: 41388

Use SysAllocString.

Note that SysAllocString takes an OLECHAR* argument, which is effectively a WCHAR*, not a CHAR*. This shouldn't be a problem unless you're compiling without UNICODE defined--but don't do that.

Upvotes: 2

James Curran
James Curran

Reputation: 103555

#include <comutil.h>

LPSTR myLpstr = "Hello World!";
_bstr_t bstr = _bstr_T(myLpstr);

It also needs library comsupp.lib

Upvotes: 3

Related Questions