我是这样写的
//.h文件
#if !defined(AFX_MANAGESTU_H__7390B43D_3BBE_45C3_BBD2_0A761B8AEBFD__INCLUDED_)
#define AFX_MANAGESTU_H__7390B43D_3BBE_45C3_BBD2_0A761B8AEBFD__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef MYAPI
#define MYAPI _declspec(dllexport)
#endif
typedef struct MStu
{
CString no;
char subject[1];
}*Stu;
BOOL WINAPI DllMain(HANDLE, DWORD, LPVOID);
class MYAPI CManageStu
{
public:
CManageStu();
virtual ~CManageStu();
void Add(Stu student);
void Delete(Stu student);
void Update(Stu student);
private:
CPtrList plist;
};
#endif // !defined(AFX_MANAGESTU_H__7390B43D_3BBE_45C3_BBD2_0A761B8AEBFD__INCLUDED_)
//.cpp文件
#include "stdafx.h"
#include "CManageStu.h"
#include "ManageStu.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CManageStu::CManageStu()
{
plist.GetHead() = NULL;
}
CManageStu::~CManageStu()
{
}
void CManageStu::Add(Stu student)
{
plist.AddTail((LPCSTR*)student);
}
void CManageStu::Delete(Stu student)
{
POSITION pos = NULL;
pos = (POSITION)plist.GetHead();
while(pos != NULL)
{
if(((Stu)pos)->no == student->no)
{
plist.RemoveAt((POSITION)pos);
free(student);
}
plist.GetNext(pos);
}
}
void CManageStu::Update(Stu student)
{
POSITION pos = NULL;
pos = (POSITION)plist.GetHead();
while(pos != NULL)
{
if(((Stu)pos)->no == student->no)
{
((Stu)pos)->no = student->no;
((Stu)pos)->subject[0] = student->subject[0];
((Stu)pos)->subject[1] = student->subject[1];
}
plist.GetNext(pos);
}
}
BOOL WINAPI DllMain(HANDLE, DWORD, LPVOID)
{
switch()
{
case DLL_PROCESS_ATTACH:
//在这里我该怎么初始化申明的结构体该怎么new???
break;
case DLL_PROCESS_DETACH:
break;
default:
}
}