sscanf_s无法获得正确的值

时间:2014-08-01 20:23:52

标签: c++ winapi visual-c++

char ListItemName[512]; //this buffer holds the IP address in the listbox
...
//Get the the current selected IP in listbox in to ListItemName
memset(ListItemName, 0, sizeof(ListItemName));
sel = SendMessage(hwndListBox, LB_GETCURSEL, 0, 0);
SendMessage(hwndListBox, LB_GETTEXT, sel, (LPARAM)ListItemName);

//
Prepare the buffer for IP Address Control
unsigned short a, b, c, d;
sscanf_s(ListItemName, "%hu.%hu.%hu.%hu", &a, &b, &c, &d); // <<-- this is the problem..
LPARAM CurAddress = MAKEIPADDRESS(a, b, c, d);
MessageBox(NULL, (LPCTSTR)ListItemName, L"IP address", MB_OK);
SendMessage(hWndIPAddress, IPM_SETADDRESS, 0, CurAddress);

我的问题是在sscanf函数中,它没有从缓冲区返回正确的值。但是当我使用messagebox显示缓冲区时,它都是正确的。

请提供建议。

谢谢!

0 个答案:

没有答案