《 VC++ 技术内幕》 dll 问题求教

山水孤狼 2010-06-18 09:50:52
《 VC++ 技术内幕》第四版,第二十一章,动态库链接,需要加入两个文件 PERSIST.cpp和PERSIST.h(是第十四章的)

在visual Studio 2008(中文)下编译。

代码如下:
//PERSIST.cpp
//Persist.cpp Persistent frame class for SDI apps
#include "stdafx.h"
#include "persist.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = _FILE_;
#endif
/////////////////////////////////////////////////
//CPersistentFrame
const CRect CPersistentFrame::s_rectDefault( 10, 10, 500, 400);//static
const char CPersistentFrame::s_profileHeading[] = "Window size";
const char CPersistentFrame::s_profileRect[] = "Rect";
const char CPersistentFrame::s_profileIcon[] = "icon";
const char CPersistentFrame::s_profileMax[] = "max";
const char CPersistentFrame::s_profileTool[] = "tool";
const char CPersistentFrame::s_profileStatus[] = "status";
IMPLEMENT_DYNAMIC(CPersistentFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CPersistentFrame, CFrameWnd)
//{{AFX_MSG_MAP(CPersistentFrame)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//////////////////////////////////////////////////////////////////////
CPersistentFrame::~CPersistentFrame()
{
m_bFirstTime = TRUE;
}
//////////////////////////////////////////////////////////////////////
/*CPersistentFrame::~CPersistentFrame()
{
}*/
//////////////////////////////////////////////////////////////////////
void CPersistentFrame::OnDestroy()
{
CString strText;
BOOL bIconic,bMaximized;
WINDOWPLACEMENT wndpl;
//gets current window position and iconized/maximized status
BOOL bRet = GetWindowPlacement(&wndpl);
if(wndpl.showCmd == SW_SHOWNORMAL){
bIconic = FALSE;
bMaximized = FALSE;
}
else if (wndpl.showCmd == SW_SHOWMAXIMIZED){
bIconic = FALSE;
bMaximized = FALSE;
}
else if (wndpl.showCmd == SW_SHOWMINIZED){
bIconic = TURE;
if(wndpl.flags){
bMaximized = TRUE;
}
else{
bMaxmized = FALSE;
}
}
strText.Format("%04d %04d %04d %04d",
wndpl.rcNormalPosition.left,
wndpl.rcNormalPosition.top,
wndpl.rcNormalPosition.right,
wndpl.rcNormalPosition.bottom);
AfxGetApp()->WriteProfileString(s_profileHeading, s_profileRect, strText);
AfxGetApp()->WriteProfileInt(s_profileHeading, s_profileIcon, bIconic);
AfxGetApp()->WriteProfileInt(s_profileHeading, s_profileMax, bMaximized);
SaveBarState(AfxGetApp()->m_pszProfileName);
CFrameWnd::OnDestroy();
}

/////////////////////////////////////////////////////////////////////////////////
void CPersistentFrame::ActivateFrame(int nCmdShow)
{
CString strText;
BOOL bIconic,bMaximized;
UINT flags;
WINDOWPLACEMENT wndpl;
CRect rect;
if(m_bFirstTime){
m_bFirstTime = FALSE;
strText = AfxGetApp()->GetProfileString(s_profileHeading, s_profileRect);
if(!strText.IsEmpty()){
rect.left = atoi((const char*)strText);
rect.top = atoi((const char*)strText +5);
rect.right = atoi((const char*)strText +10);
rect.bottom = atoi((const char*)strText +15);
}
else{
rect = s_rectDefault;
}
bIconic = AfxGetApp()->GetProfileInt(s_profileHeading, s_profileIcon, 0);
bMaximized = AfxGetApp()->GetProfileInt(s_profileHeading, s_profileMax, 0);
if(bIconic){
nCmdShow = SW_SHOWMINNOACTIVE;
if(bMaximized){
flags = WPF_RESTORETOMAXIMIZED;
}
else {
flags = WPF_SETMINPOSITION;
}
}
else {
if(bMaximized){
nCmdShow = SW_SHOWMAXIMIZED;
flags = WPF_RESTORETOMAXIMIZED;
}
else {
nCmdShow = SW_NORMAL;
flags = WPF_SETMINPOSITION;
}
}
wndpl.length = sizeof(WINDOWPLACEMENT);
wndpl.showCmd = nCmdShow;
wndpl.flags = flags;
wndpl.ptMinPosition = CPoint(0, 0);
wndpl.ptMaxPosition = CPoint(-::GetSystemMetrics(SM_CXBORDER), -::GetSystemMetrics(SM_CYBORDER));
wndpl.rcNormalPosition = rect;
//sets window's position and minimized status
BOOL bRet = SetWindowPlacement(&wndpl);
}
CFrameWnd::ActivateFrame(nCmdShow);
}



错误如下:
1>正在编译...
1>PERSIST.cpp
1>d:\work\mfc\ex21a\ex21a\persist.cpp(7) : error C2065: “_FILE_”: 未声明的标识符
1>d:\work\mfc\ex21a\ex21a\persist.cpp(35) : error C2509: “OnDestroy”: 成员函数没有在“CPersistentFrame”中声明
1> d:\work\mfc\ex21a\ex21a\persist.h(5) : 参见“CPersistentFrame”的声明
1>d:\work\mfc\ex21a\ex21a\persist.cpp(80) : error C2664: “CWinApp::GetProfileStringW”: 不能将参数 1 从“const char [12]”转换为“LPCTSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>d:\work\mfc\ex21a\ex21a\persist.cpp(82) : error C2440: “类型转换”: 无法从“CString”转换为“const char *”
1> 没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符
1>d:\work\mfc\ex21a\ex21a\persist.cpp(83) : error C2440: “类型转换”: 无法从“CString”转换为“const char *”
1> 没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符
1>d:\work\mfc\ex21a\ex21a\persist.cpp(84) : error C2440: “类型转换”: 无法从“CString”转换为“const char *”
1> 没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符
1>d:\work\mfc\ex21a\ex21a\persist.cpp(85) : error C2440: “类型转换”: 无法从“CString”转换为“const char *”
1> 没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符
1>d:\work\mfc\ex21a\ex21a\persist.cpp(90) : error C2664: “CWinApp::GetProfileIntW”: 不能将参数 1 从“const char [12]”转换为“LPCTSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>d:\work\mfc\ex21a\ex21a\persist.cpp(91) : error C2664: “CWinApp::GetProfileIntW”: 不能将参数 1 从“const char [12]”转换为“LPCTSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>生成日志保存在“file://d:\work\MFC\ex21a\ex21a\Debug\BuildLog.htm”
1>ex21a - 9 个错误,0 个警告

请问高手:如何解决?
...全文
151 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
CloudmmFly 2010-07-18
  • 打赏
  • 举报
回复
还是用VC6.0吧,要不你会发现有一大堆问题.
捕鲸叉 2010-07-18
  • 打赏
  • 举报
回复
建议用低一点的VC版本来编译
山水孤狼 2010-06-18
  • 打赏
  • 举报
回复
ytu2006123(csdn是个学习的好地方)
persist.h和PERSIST.cpp文件都已经拷贝在项目根目录下。


zhanshen2891 2010-06-18
  • 打赏
  • 举报
回复
打开工程属性,有个关于编码的设置,2008默认是UNICODE的,改为多字节的

那些不能转换的错误,改为,CString有个GetBuf
ytu2006123 2010-06-18
  • 打赏
  • 举报
回复
persist.h文件没有放到PERSIST.cpp文件的相同目录下吧

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧