Community discussion forum

How to convert unsigned long to const char * [VC++6]

  • 8 months ago
    I am having some issues using .gethostbyname(...) and not sure how to fix it with the older version (6) of Visual C++. I have the following code: [Code] unsigned long ipaddr = INADDR_NONE; ipaddr = inet_addr(pszHostName); LPHOSTENT lphost = gethostbyname (ipaddr); [/Code] This produces the following error: error C2664: 'gethostbyname' : cannot convert parametr 1 from 'unsigned long' to 'const char *' Conversion from integral type to pointer type requires reinterpret_cast C-style cast or function-style cast Now, if I was using VC++7 and above I could simply use CT2A and solve all my problems, but to my knowledge this is not supported in C++6. So how can I make this cast work? Any help would be greatly appreciated. Thanks,
    Post was edited on 27/03/2009 23:51:03 Report abuse
  • 8 months ago
    I've got a pretty good idea what gethostbyname() does, and obviously it is not working (or I wouldn't be getting the errors). This might help (I forgot to post a bit of code): [Code] BOOL ping(LPCTSTR pszHostName) { unsigned long ipaddr = INADDR_NONE; ipaddr = inet_addr(pszHostName); if (ipaddr == INADDR_NONE) { CT2A szAsciiHostName(pszHostName); LPHOSTENT lphost = gethostbyname (szAsciiHostName); ... [/Code] But I don't have CT2A to do it ... so this approach doesn't work, I need to find a way to mimic it.... Thanks,

Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback