调用memcpy函数出错, Debug报错信息:Unhandled exception in SocketClient.exe 0xc

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(&amp;hostnm, hostaddr, sizeof(struct hostent));
break;
}
break;
在memcpy这句话上报错,Debug报错信息:Unhandled exception in SocketClient.exe 0xc00000005 Access Violation
 
hostaddr和hostnm在那定义的?
 
#include "stdafx.h"
#include <malloc.h>
#include <memory.h>
//#include <windows.h>
#include <winsock.h>

#define USERPORT 10002
#define IDM_START 101
#define IDM_EXIT 102
#define UM_SOCK WM_USER + 0x100
#define MAJOR_VERSION 1
#define MINOR_VERSION 2
#define WSA_MAKEWORD(x, y) ((y) * 256 + (x))
#define _fmemcpy memcpy

HANDLE hInst;
char server_address[256] = {0};
char buffer[1024];
char FAR *lpBuffer = &amp;buffer[0];
SOCKET s = 0;
struct sockaddr_in dst_addr;
struct hostent far *hostaddr;
struct hostent hostnm;
struct servent FAR *sp;
int count = 0;
 
收mail吧
我只有今天又时间
 
回了,谢谢!
 
if (hostaddr = NULL)
应为
if (hostaddr == NULL)
 
谢谢,我试试
 
谢谢,已经试通,就是if (hostaddr == NULL) 的事情[:)]
 
楼上说的对
 

Similar threads

顶部