|
|
|
date: Tue, 22 Jan 2008 02:47:25 -0800 (PST),
group: microsoft.public.platformsdk.com_ole
back
How to extract char from VT_BSTR?
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
date: Tue, 22 Jan 2008 02:47:25 -0800 (PST)
author: Atiz
Re: How to extract char from VT_BSTR?
"Atiz" wrote in message news:d04a9ee9-bb99-4791-83b8-43c1e062b57f@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
date: Tue, 22 Jan 2008 08:46:35 -0800
author: Brian Muth
Re: How to extract char from VT_BSTR?
On Jan 23, 12:46 am, "Brian Muth" wrote:
> "Atiz" wrote in messagenews:d04a9ee9-bb99-4791-83b8-43c1e062b57f@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
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
date: Tue, 22 Jan 2008 22:48:57 -0800 (PST)
author: Atiz
|
|