代码是一个dll动态链接库
源代码如下:
#include "stdafx.h"
#include "GetOth2CNC.h"
//#include "CmdSocket.h"
#include "DataSocket.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endifBEGIN_MESSAGE_MAP(CGetOth2CNCApp, CWinApp)
//{{AFX_MSG_MAP(CGetOth2CNCApp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()CGetOth2CNCApp::CGetOth2CNCApp()
{
m_dataSocket = new CDataSocket(this);
}CGetOth2CNCApp theApp;extern "C" __declspec(dllexport)long WINAPI GetOth2Status(long CNCType, char *IPAddress, unsigned short PortNo, long TimeOut, StatusData* data ) ;
long WINAPI GetOth2Status( long CNCType,
char *IPAddress,
unsigned short PortNo,
long TimeOut, StatusData *data )
{ HKEY hKey; LPBYTE AlarmNo=new BYTE[4];
DWORD type=REG_SZ;
DWORD length=4; if (!AfxSocketInit())
{
theApp.m_dataSocket->Close();
delete theApp.m_dataSocket;
return -1;
} if (!theApp.m_dataSocket->connect(IPAddress, PortNo))
{
//theApp.m_dataSocket.Close();
theApp.m_dataSocket->Close();
delete theApp.m_dataSocket;
return -1;
}
if(theApp.m_dataSocket->sendCommand ("<ncda><req>yes</req><var>status,prg,sub,mode,mmode</var></ncda>")==false)
{
theApp.m_dataSocket->Close();
delete theApp.m_dataSocket;
//AfxMessageBox(m_StrStatus);
return -1;
}
MyBuf.status= theApp.XMLParse(theApp.m_dataSocket->Result_value, "status");
memcpy( data, &MyBuf, sizeof( StatusData ) ) ;
return 0;
}
int CGetOth2CNCApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
//theApp.m_dataSocket.Close();
return CWinApp::ExitInstance();
}
错误信息如下:
compiling...
GetOth2CNC.cpp
Linking...
Creating library Release/GetOth2CNC.lib and object Release/GetOth2CNC.exp
GetOth2CNC.obj : error LNK2001: unresolved external symbol "public: __thiscall CDataSocket::CDataSocket(class CGetOth2CNCApp *)" (??0CDataSocket@@QAE@PAVCGetOth2CNCApp@@@Z)
Release/GetOth2CNC.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.GetOth2CNC.dll - 2 error(s), 0 warning(s)
这是什么错误?怎么解决?
源代码如下:
#include "stdafx.h"
#include "GetOth2CNC.h"
//#include "CmdSocket.h"
#include "DataSocket.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endifBEGIN_MESSAGE_MAP(CGetOth2CNCApp, CWinApp)
//{{AFX_MSG_MAP(CGetOth2CNCApp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()CGetOth2CNCApp::CGetOth2CNCApp()
{
m_dataSocket = new CDataSocket(this);
}CGetOth2CNCApp theApp;extern "C" __declspec(dllexport)long WINAPI GetOth2Status(long CNCType, char *IPAddress, unsigned short PortNo, long TimeOut, StatusData* data ) ;
long WINAPI GetOth2Status( long CNCType,
char *IPAddress,
unsigned short PortNo,
long TimeOut, StatusData *data )
{ HKEY hKey; LPBYTE AlarmNo=new BYTE[4];
DWORD type=REG_SZ;
DWORD length=4; if (!AfxSocketInit())
{
theApp.m_dataSocket->Close();
delete theApp.m_dataSocket;
return -1;
} if (!theApp.m_dataSocket->connect(IPAddress, PortNo))
{
//theApp.m_dataSocket.Close();
theApp.m_dataSocket->Close();
delete theApp.m_dataSocket;
return -1;
}
if(theApp.m_dataSocket->sendCommand ("<ncda><req>yes</req><var>status,prg,sub,mode,mmode</var></ncda>")==false)
{
theApp.m_dataSocket->Close();
delete theApp.m_dataSocket;
//AfxMessageBox(m_StrStatus);
return -1;
}
MyBuf.status= theApp.XMLParse(theApp.m_dataSocket->Result_value, "status");
memcpy( data, &MyBuf, sizeof( StatusData ) ) ;
return 0;
}
int CGetOth2CNCApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
//theApp.m_dataSocket.Close();
return CWinApp::ExitInstance();
}
错误信息如下:
compiling...
GetOth2CNC.cpp
Linking...
Creating library Release/GetOth2CNC.lib and object Release/GetOth2CNC.exp
GetOth2CNC.obj : error LNK2001: unresolved external symbol "public: __thiscall CDataSocket::CDataSocket(class CGetOth2CNCApp *)" (??0CDataSocket@@QAE@PAVCGetOth2CNCApp@@@Z)
Release/GetOth2CNC.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.GetOth2CNC.dll - 2 error(s), 0 warning(s)
这是什么错误?怎么解决?
源代码如下:DataSocket.h文件:#if !defined(AFX_DATASOCKET_H__00CD3021_FA86_4C19_BA99_7C560CB9137D__INCLUDED_)
#define AFX_DATASOCKET_H__00CD3021_FA86_4C19_BA99_7C560CB9137D__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// DataSocket.h : header file
//#include "CmdSocket.h"
//#include "GetOth2CNC.h"class CGetOth2CNCApp;
/////////////////////////////////////////////////////////////////////////////
// CCmdSocket command targetclass CDataSocket : public CCmdSocket
{
// Attributes
public:// Operations
public:
//CDataSocket(CKeyAppletXCtrl* ctrl);
CDataSocket(CGetOth2CNCApp* ctrl);
virtual ~CDataSocket();// Overrides
public:
CGetOth2CNCApp* m_ctrl;
CString m_StrStatus;
CString m_StrPrg;
CString m_StrSub;
CString m_StrMode;
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDataSocket)
public:
virtual void OnReceive(int nErrorCode);
//}}AFX_VIRTUAL // Generated message map functions
//{{AFX_MSG(CDataSocket)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG// Implementation
protected:
};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_DATASOCKET_H__00CD3021_FA86_4C19_BA99_7C560CB9137D__INCLUDED_)
DataSocket.cpp文件:/ DataSocket.cpp : implementation file
// Class realizes asynchronous communication with CNC server. Derived from CCmdSocket#include "stdafx.h"
#include "DataSocket.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif//#include "KeyAppletXCtl.h"
//#include "GetOth2CNC.h"
/////////////////////////////////////////////////////////////////////////////
// CCmdSocket
#include "GetOth2CNC.h"CDataSocket::CDataSocket(CGetOth2CNCApp* ctrl)
: CCmdSocket()
{
m_ctrl = ctrl;
}CDataSocket::~CDataSocket()
{
}
// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CDataSocket, CCmdSocket)
//{{AFX_MSG_MAP(CDataSocket)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0/////////////////////////////////////////////////////////////////////////////
// CCmdSocket member functionsvoid CDataSocket::OnReceive(int nErrorCode)
{
//int i=1;
// TODO: Add your specialized code here and/or call the base class
// StatusData* MyStatus;
CMapStringToString* data = new CMapStringToString;
CString value;
// char buffer[20];
char buff[4096];
int nRead;
nRead = Receive(buff, 4096);
buff[nRead] = 0; //terminate the string
if (nRead == SOCKET_ERROR)
{
if (GetLastError() != WSAEWOULDBLOCK)
{
AfxMessageBox ("Error occurred");
Close();
}
}
else
{
char *pStart, *pFound;
pStart = buff;
int nRest = nRead;
while (true)
{
pFound = (char*)memchr(pStart, '\n', nRest);
if (pFound == NULL)
break;
*pFound++ = '\0';
data=DataFromXML(CString(pStart));
data->Lookup("OBJECT_NAME", value);
if (value == "alarm")
{
AfxMessageBox("ok",MB_OK,NULL);
// i = i+1;
/* if (data->Lookup("status", m_StrStatus))
{
}
if (data->Lookup("sub", m_StrSub))
{
}
if (data->Lookup("prg", m_StrPrg))
{
}
if (data->Lookup("mode", m_StrMode))
{
}*/
} nRest -= pFound - pStart;
pStart = pFound;
}
}
CSocket::OnReceive(nErrorCode);
}