C/C++问题?
本人对C/C++了解不多,下面有四句请高手给予解释
(摘抄<<精通Visual c++5.0编程>>)
//////////////////////////////////////////////////////////////////////////////////
//LineGenMethod.h
#if !defined LINEGENMETHOD_H
#define LINEGENMETHOD_H
#include "windows.h"
#include "afxtempl.h"
#include "LineGenMethodDlg.h"
typedef BOOL (*pLinePoint)(int,float*,float*,int*,float*,float*);/////////////////////请解释
class CLineGenMethod
{
public:
char m_filename[256];
struct Gen
{
char DllFileName[256];
char Name[256];
HINSTANCE hInstance;
Gen()
{
hInstance=NULL;
}
};
typedef CTypedPtrList<CPtrList,Gen*>GenBaseList;
GenBaseList GenList;
CLineGenMethod(char *filename);
~CLineGenMethod();
pLinePoint FindFun(CString& name);/////////////////////请解释
UINT GetGenCount();
BOOL Load();
BOOL Save();
BOOL Add(char* dllfilename,char* name);
void DeleteAll();
void SetDlg(CWnd* pParent);
};
#endif
//////////////////////////////////////////////////////////////////////////////////
//LineGenMethod.cpp
#include "stdafx.h"
#include "Chart.h"
#include "LineGenMethod.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CLineGenMethod::CLineGenMethod(char* filename)
{
strcpy(m_filename,filename);
Load();
}
CLineGenMethod::~CLineGenMethod()
{
Save();
DeleteAll();
}
BOOL CLineGenMethod::Load()
{
CFile f;
CFileException e;
if(!f.Open(m_filename,CFile::modeRead,&e))
{
#ifdef _DEBUG
afxDump<<"File could not de opened"<<e.m_cause<<"\n";
#endif
return FALSE;
}
UINT Count;
f.Read(&Count,sizeof UINT);
for(UINT i=0;i<Count;i++)
{
Gen newGen;
f.Read(&newGen,sizeof Gen);
Add(newGen.DllFileName,newGen.Name);
}
f.Close();
return TRUE;
}
BOOL CLineGenMethod::Add(char* dllfilename,char* name)
{
Gen*pGen=new Gen;
strcpy(pGen->DllFileName,dllfilename);
strcpy(pGen->Name,name);
pGen->hInstance=NULL;
HINSTANCE hLine=::LoadLibrary(dllfilename);
if(hLine==NULL)
{
char str[256];
sprintf(str,"CAn not Load File%s!",dllfilename);
::MessageBox(NULL,str,NULL,MB_OK|MB_ICONEXCLAMATION);
delete pGen;
return FALSE;
}
else
{
pLinePoint f=(pLinePoint)::GetProcAddress(hLine,"LinePoint");/////////////////////请解释
if(f==NULL)
{
char str[256];
sprintf(str,"File%s is Error!",dllfilename);
::MessageBox(NULL,str,NULL,MB_OK|MB_ICONEXCLAMATION);
::FreeLibrary(hLine);
delete pGen;
return FALSE;
}
else
{
pGen->hInstance=hLine;
GenList.AddTail(pGen);
return TRUE;
}
}
}
BOOL CLineGenMethod::Save()
{
CFile f;
CFileException e;
if(!f.Open(m_filename,CFile::modeWrite|CFile::modeCreate,&e))
{
#ifdef _DEBUG
afxDump<<"File could not de opened"<<e.m_cause<<"\n";
#endif
return FALSE;
}
UINT Count=GenList.GetCount();
f.Write(&Count,sizeof UINT);
POSITION pos=GenList.GetHeadPosition();
while(pos)
{
Gen* pGen=GenList.GetNext(pos);
f.Write(pGen,sizeof Gen);
}
f.Close();
return TRUE;
}
void CLineGenMethod::DeleteAll()
{
while(!GenList.IsEmpty())
{
Gen* pGen=GenList.RemoveHead();
::FreeLibrary(pGen->hInstance);
delete pGen;
}
}
UINT CLineGenMethod::GetGenCount()
{
return GenList.GetCount();
}
pLinePoint CLineGenMethod::FindFun(CString& name)
{
POSITION pos=GenList.GetHeadPosition();
while(pos)
{
Gen * pGen=GenList.GetNext(pos);
if(name==pGen->Name)
return (pLinePoint)::GetProcAddress(pGen->hInstance,"LinePoint");/////////////////////请解释
}
return NULL;
}
void CLineGenMethod::SetDlg(CWnd* pParent)
{
CLineGenMethodDlg Dlg;
Dlg.SetInitData(this);
Dlg.DoModal();
}