473,387 Members | 1,687 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

convert BSTR to a long

I have a BSTR with the string "123". I need this as a long (or UINT).
How can I do this? I am a newbie, does it show?

Thanks,
Tom
Jul 19 '05 #1
3 7324

"tojo" <To**@hotmail.com> wrote in message
news:MP************************@news.t-online.de...
I have a BSTR with the string "123". I need this as a long (or UINT).
How can I do this? I am a newbie, does it show?

Thanks,
Tom


Loop though the string one character at a time, each time round the loop
multiply the value you have so far by 10, and add the value of the latest
digit.

I.e. in pseudo code

long val = 0;
while (more digits)
{
val *= 10;
val += next digit;
}

In your example val will go like this

val = 0;
val = 0; // times 10
val = 1; // plus digit '1'
val = 10; // times 10
val = 12; // plus digit '2'
val = 120; // times 10
val = 123; // plus digit '3'

Get the picture?

john
Jul 19 '05 #2
> I have a BSTR with the string "123". I need this as a long (or UINT).
How can I do this? I am a newbie, does it show?


It does indeed.

Questions on standard C++ should be asked here.

Questions on Microsoft technology (like BSTR) should be asked on Microsofts
news server: msnews.microsoft.com. There are 22+ newsgroups devoted to VC++
alone.

Stephen Howe

Jul 19 '05 #3
tojo wrote:
I have a BSTR with the string "123". I need this as a long (or UINT).
How can I do this? I am a newbie, does it show?

Thanks,
Tom


First, you'll need to convert the BSTR to an ordinary sequence of
characters (wcstombs I think should do it for you - the docs are your
friend).

Then just use atoi/atol to convert it.

Good luck.
Tom L

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: David Lawson | last post by:
I know how to conver a string to an array of strings, but I need to convert an ascii string to an array of integers (really unsigned chars). Eg, $str ="ABC"; needs to convert to something...
1
by: Chris | last post by:
I am not sure if this is the right newsgroup. But does anyone know what is the difference between a BSTR and a LPOLESTR? The only thing I could find out is that the advantage of taking BSTR...
5
by: Karthik | last post by:
Hello, How can I convert a BSTR data type to std::string??? Thanks a much! Karthik
2
by: banski | last post by:
Hi, Im trying to find out how to convert a SYSTEMTIME to BSTR. Cant find out how to do that. Hopefully some of you could help me out. Best regards Thomas
7
by: Gilad Walden | last post by:
I use C# in .NET framework. I have an ActiveX implemented in C++ that has a COM interface method that gets as it’s out parameter a BSTR* . The interop translates this BSTR* into C# string. From...
5
by: bluter | last post by:
We have server components which were created by a third party and compiled in VC++5 (sp3). They run fine on NT4 and 2000, however during testing of our migration to Server 2003, these components...
37
by: Egbert Nierop \(MVP for IIS\) | last post by:
In win32 mode, a BSTR was UINT length prefixed and terminated exactly by a zero char. So if you allocated "Hello World" that would allocate 28 bytes. In x64 and (IA64 as well) it would become...
1
by: Tao | last post by:
hi.. Group, is there anyone know how to convert wstring to BSTR? thanks.
5
by: Maxim | last post by:
Hi all, I'm calling a COM Interface method that returnes SafeArray wrapped into variant. Is it possible to convert it to managed array? Because working with SAFEARRAY directly is a bit...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.