Link to home
Start Free TrialLog in
Avatar of loyaliser
loyaliserFlag for United States of America

asked on

Converting data types (again)...

I have this function in some .h file included in my ATL COM program:

function(char *);

and need to pass this variable in the ATL COM code into the "char *" part of the above function:

BSTR SomeData;

How do I do that?

So, I need to call this function in my ATL COM code like this:

BSTR SomeData;

// Conver BSTR to char (what is the code needed here)

function(charOfSomeData);

Thanks...
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of loyaliser

ASKER

I will give it a try tomorrow morning... thanks...
I hope you don't mind, but what would be the code for doing it the other way around... char [] to BSTR?

Thanks...
Use the ATL conversion macro A2BSTR.

USES_CONVERSION;
A2BSTR();

Or, simply use _bstr_t since it has a constructor

_bstr_t( const char* s2 ) throw( _com_error );

and use _bstr_t in place of BSTR.

You may also use CComBSTR class in ATL.