Q
qince
Unregistered / Unconfirmed
GUEST, unregistred user!
调用memcpy函数出错, Debug报错信息:Unhandled exception in SocketClient.exe 0xc00000005 Access Violation (300分)<br />自己照书写了一个Socket的例子,但是死活调不通,再加上没用过VC,代码如下:
switch(message)
{
case WM_USER:
{
WORD wMajorVersion, wMinorVersion;
LPWSADATA lpmyWSAData;
WORD VersionReqd;
// int ret;
wMajorVersion = MAJOR_VERSION;
wMinorVersion = MINOR_VERSION;
VersionReqd = WSA_MAKEWORD(wMajorVersion, wMinorVersion);
lpmyWSAData = ((LPWSADATA)malloc(sizeof(WSADATA)));
Status = WSAStartup(wMajorVersion,lpmyWSAData);
if (Status != 0)
{
AlertUser(hWnd, "WSAStartup()函数调用失败/n");
PostQuitMessage(0);
}
hostaddr = gethostbyname(server_address);
if (hostaddr = NULL)
{
AlertUser(hWnd, "gethostbyName调用失败/n");
WSACleanup();
PostQuitMessage(0);
}
memcpy(&hostnm, hostaddr, sizeof(struct hostent));
break;
}
break;
在memcpy这句话上报错,Debug报错信息:Unhandled exception in SocketClient.exe 0xc00000005 Access Violation
switch(message)
{
case WM_USER:
{
WORD wMajorVersion, wMinorVersion;
LPWSADATA lpmyWSAData;
WORD VersionReqd;
// int ret;
wMajorVersion = MAJOR_VERSION;
wMinorVersion = MINOR_VERSION;
VersionReqd = WSA_MAKEWORD(wMajorVersion, wMinorVersion);
lpmyWSAData = ((LPWSADATA)malloc(sizeof(WSADATA)));
Status = WSAStartup(wMajorVersion,lpmyWSAData);
if (Status != 0)
{
AlertUser(hWnd, "WSAStartup()函数调用失败/n");
PostQuitMessage(0);
}
hostaddr = gethostbyname(server_address);
if (hostaddr = NULL)
{
AlertUser(hWnd, "gethostbyName调用失败/n");
WSACleanup();
PostQuitMessage(0);
}
memcpy(&hostnm, hostaddr, sizeof(struct hostent));
break;
}
break;
在memcpy这句话上报错,Debug报错信息:Unhandled exception in SocketClient.exe 0xc00000005 Access Violation