Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to extract char from VT_BSTR?

238 views
Skip to first unread message

Atiz

unread,
Jan 22, 2008, 5:47:25 AM1/22/08
to
Hi, I have an OPC client.
I used a server to send value to the OPC client whereby it detects the
value.

The OPC client is able to detect the value as a VT_BSTR.
The function which detects the value as a VT_BSTR has VARIANT* pValue
as a parameter.
When this pValue is a VT_BSTR type, I have trouble extracting the
correct value out.

Currently my method does this:

BSTR bstr = V_BSTR(pValue);
int a = SysStringLen(bstr)+1;
char *ansistr = new char[a];
result = ::WideCharToMultiBYte(CP_ACP, 0, bstr, -1, ansistr, a, NULL,
NULL);

I tried to print out

LOG4CPLUS_DEBUG(logPacket, *V_BSTR(pValue));
LOG4CPLUS_DEBUG(logPacket, bstr);
but the value is always different and is not the value that is sent
over to the OPC client.

How can I get the correct value out from pValue?

TIA,
Atiz

Brian Muth

unread,
Jan 22, 2008, 11:46:35 AM1/22/08
to

"Atiz" <fleet...@gmail.com> wrote in message news:d04a9ee9-bb99-4791...@h11g2000prf.googlegroups.com...

> Hi, I have an OPC client.
> I used a server to send value to the OPC client whereby it detects the
> value.
>
> The OPC client is able to detect the value as a VT_BSTR.
> The function which detects the value as a VT_BSTR has VARIANT* pValue
> as a parameter.
> When this pValue is a VT_BSTR type, I have trouble extracting the
> correct value out.
>
> Currently my method does this:
>
> BSTR bstr = V_BSTR(pValue);
> int a = SysStringLen(bstr)+1;
> char *ansistr = new char[a];
> result = ::WideCharToMultiBYte(CP_ACP, 0, bstr, -1, ansistr, a, NULL,
> NULL);
>

This coding is correct, assuming pValue is a VARIANT* containing a BSTR as you describe. I'm wondering if there is an issue with the
way you are trying to print it out with LOG4CPLUS_DEBUG, of which I know nothing about.

HTH

Brian


Atiz

unread,
Jan 23, 2008, 1:48:57 AM1/23/08
to
On Jan 23, 12:46 am, "Brian Muth" <bm...@mvps.org> wrote:
> "Atiz" <fleetfoo...@gmail.com> wrote in messagenews:d04a9ee9-bb99-4791...@h11g2000prf.googlegroups.com...

Hi Brian,

I printed out the values so I can see that I am passing the correct
value to another server. I tried using Factorysoft OPC client and it
was able to get the correct value from the server.
Let's say I send a string "1" over to the client. I can't get the
value "1" from bstr. On debugging, I can only see that pValue is a
BSTR with some address pointing to some weird values which is what I
also saw in my debug statements, so I can safely say there is no issue
with LOG4CPLUS_DEBUG.

Atiz

0 new messages