Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
platform
active.directory
adsi
adsi.iis-admin
base
com_ole
complus_mts
component_svcs
database
directx
gdi
graphics_mm
internet.client
internet.server
internet.server.isapi-dev
localization
mapi
messaging
msi
mslayerforunicode
multimedia
networking
networking.ipv6
sdk_install
security
shell
telephony.tapi_2
telephony.tapi_3
telephony.tsp
telephony.wte
tools
ui
ui_shell
win_base_svcs
win16
  
 
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

Re: How to extract char from VT_BSTR?   
"Atiz"  wrote
>
> 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.
>

I really don't follow anything you are saying and how it relates to the code fragment that you posted. Are you claiming that pValue 
correctly contains the string value but the conversion to ANSI is failing? If so, why not single-step through the code with the 
debugger and see where it is going wrong?

Brian


> Atiz
date: Wed, 23 Jan 2008 08:58:31 -0800   author:   Brian Muth

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us