Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1108
  • Last Modified:

GetDlgItemInt fail when user enter more than 10 digits.

I'm using vs2005 but only win32 libraries.

I have a IEdBoxEditor control.  If I enter more than 10 digits of interger number then my code below would fail to get the data.  success is return as 0.  How can correct this problem so there is no limit to the digits entered?  Thanks.

      intRet = (int)GetDlgItemInt(hwndDialog,IDC_INDEPENDENT_ENTRY_ID,&success, TRUE);
0
lapucca
Asked:
lapucca
  • 2
  • 2
1 Solution
 
RaymunCommented:
use long
0
 
lapuccaAuthor Commented:
Tried it but it still doesn't work.  

longRet = (long)GetDlgItemInt(hwndDialog,IDC_INDEPENDENT_ENTRY_ID,&success, TRUE);

Thanks.
0
 
jkrCommented:
That won't work since you still cast an int to a long, which leave the int limitations. Get that input as a string and convert it, e.g.

#include <stdlib.h>

//...

char acText [255];
char pcCnvEnd;
GetDlgItemText(hwndDialog,IDC_INDEPENDENT_ENTRY_ID,acText, sizeof(acText));

longRet = strtol(acText,&pcCnvEnd,10);

if (NULL == *pcCnvEnd) {

  // conversion successful, it is a valid integer value
}


0
 
jkrCommented:
Does that still cause trouble?
0
 
lapuccaAuthor Commented:
Sorry jkr, I haven't tried it.  I will when I return to work on Monday and will let you know.  Thanks.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now