You must parse the string to get the four elements, convert these to numbers, and combine the numbers to a DWORD (assuming an IPv4 address in dotted notation; your
CString.Format
example misses the periods in it).
There are various methods to perform the parsing:
unsigned bytes[4];
int fields = _stscanf(str.GetString(), _T("%u.%u.%u.%u"),
bytes+3, bytes+2, bytes+1, bytes);
unsigned long bytes[4];
LPCTSTR parse = str.GetString();
LPTSTR endptr;
int i;
for (i = 3; parse != NULL && i >= 0; i--)
{
bytes[i] = _tcstoul(parse, &endptr, 10);
if (*endptr == _T('.'))
parse = endptr + 1;
else
parse = NULL;
}
Besides the above examples there are more functions that can be used to parse the string like
CStringT::Tokenize[
^] and regular expressions (
<regex>[
^]).
Finally combine the four numbers to a DWORD:
DWORD dwIP = bytes[0] + (bytes[1] << 8) + (bytes[2] << 16) + (bytes[3] << 24);