×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

strol always returns error 122

strol always returns error 122

strol always returns error 122

(OP)
environment: Windows 7, 64 bit, Visual Studio 2008, C++

CODE

string t_string;
...
long long temp = strol( t_string.c_str(), NULL, 10 )
long error = GetLastError();
*return_value = (int) temp;

After finding that atoi returns 0 on error, I shifted to strol because it sets the system error value.  However, if the string to be converted is not "0" then the error is always 122.  Help files explaine this as: ERROR_INSUFFICIENT_BUFFER, The data area passed to a system call is too small.

I changed the return value from an int, then to a long, then to a long long with no effect.

In the above example, the string to be converted shows up in the debugger as "5508" or "16" or other such strings.  Some not shown code isolates the string to be converted and puts it in t_string.   The dugger shows that the conversion is correct even when GetLastError returns 122.

We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
 

RE: strol always returns error 122

GetLastError is for Windows functions.  strtol is no a windows function.  You should be using errno.

CODE

#include <errno.h>
...
string t_string;
...
long long temp = strol( t_string.c_str(), NULL, 10 )
long error = errno;
*return_value = (int) temp;
You can get the error strings using strerror(error)

RE: strol always returns error 122

(OP)
Thank you, I will make some code changes.

Since the value from GetLastError() was not zero, I think that implies that there is an error.  Perhaps I had best check the previous code.  

We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
 

RE: strol always returns error 122

Incidentally, strtol (not strol, of course;) returns long (not long long) value.
Use non-standard VC++ function _strtoi64 to get possible long long (64-bit) values correctly...
 

RE: strol always returns error 122

(OP)
Hello ArkM,
When GetLastError() returned 122,  ERROR_INSUFFICIENT_BUFFER, I tried the only thing I could think of, make the return variable longer.  I with change to your recommended errorno() on Monday.
Thank you.

We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close