全局变量:
CString g_strFileName = "1.bmp";函数:
void CapPic(CString strPicFileName)
{
g_strFileName = strPicFileName; // 第一次调用正常, 第二次调用报错!
... ...
}调用:
第一次调用: CapPic("2.bmp"); // 没有问题
第二次调用: CapPic("3.bmp"); // 在CapPic()中报错!跟踪下去是因为CString "=" 操作符中Release()错误:
const CString& CString::operator=(const CString& stringSrc)
{
if (m_pchData != stringSrc.m_pchData)
{
if ((GetData()->nRefs<0&&GetData()!=_afxDataNil)||stringSrc.GetData()-nefs < 0)
{ ... }
else
{
// can just copy references around
Release(); // 此处报错! , 见Release()函数.
ASSERT(stringSrc.GetData() != _afxDataNil);
m_pchData = stringSrc.m_pchData;
InterlockedIncrement(&GetData()->nRefs);
}
}
return *this;
}// CString::Release()
void CString::Release()
{
if (GetData() != _afxDataNil)
{
ASSERT(GetData()->nRefs != 0);
if (InterlockedDecrement(&GetData()->nRefs) <= 0)
FreeData(GetData()); //此处报错,见FreeData()函数.
Init();
}
}// CString::FreeData()
void FASTCALL CString::FreeData(CStringData* pData)
{
#ifndef _DEBUG
int nLen = pData->nAllocLength;
if (nLen == 64)
_afxAlloc64.Free(pData);
else if (nLen == 128)
_afxAlloc128.Free(pData);
else if (nLen == 256)
_afxAlloc256.Free(pData);
else if (nLen == 512)
_afxAlloc512.Free(pData);
else
{
ASSERT(nLen > 512);
delete[] (BYTE*)pData;
}
#else
delete[] (BYTE*)pData; // 此处报错!!!
#endif
}// delete
void __cdecl operator delete(void* p)
{
#if !defined(_AFX_NO_DEBUG_CRT) && defined(_DEBUG)
_free_dbg(p, _NORMAL_BLOCK); // 此处报错!!!
#else
free(p);
#endif
}请大侠们帮助!
CString g_strFileName = "1.bmp";函数:
void CapPic(CString strPicFileName)
{
g_strFileName = strPicFileName; // 第一次调用正常, 第二次调用报错!
... ...
}调用:
第一次调用: CapPic("2.bmp"); // 没有问题
第二次调用: CapPic("3.bmp"); // 在CapPic()中报错!跟踪下去是因为CString "=" 操作符中Release()错误:
const CString& CString::operator=(const CString& stringSrc)
{
if (m_pchData != stringSrc.m_pchData)
{
if ((GetData()->nRefs<0&&GetData()!=_afxDataNil)||stringSrc.GetData()-nefs < 0)
{ ... }
else
{
// can just copy references around
Release(); // 此处报错! , 见Release()函数.
ASSERT(stringSrc.GetData() != _afxDataNil);
m_pchData = stringSrc.m_pchData;
InterlockedIncrement(&GetData()->nRefs);
}
}
return *this;
}// CString::Release()
void CString::Release()
{
if (GetData() != _afxDataNil)
{
ASSERT(GetData()->nRefs != 0);
if (InterlockedDecrement(&GetData()->nRefs) <= 0)
FreeData(GetData()); //此处报错,见FreeData()函数.
Init();
}
}// CString::FreeData()
void FASTCALL CString::FreeData(CStringData* pData)
{
#ifndef _DEBUG
int nLen = pData->nAllocLength;
if (nLen == 64)
_afxAlloc64.Free(pData);
else if (nLen == 128)
_afxAlloc128.Free(pData);
else if (nLen == 256)
_afxAlloc256.Free(pData);
else if (nLen == 512)
_afxAlloc512.Free(pData);
else
{
ASSERT(nLen > 512);
delete[] (BYTE*)pData;
}
#else
delete[] (BYTE*)pData; // 此处报错!!!
#endif
}// delete
void __cdecl operator delete(void* p)
{
#if !defined(_AFX_NO_DEBUG_CRT) && defined(_DEBUG)
_free_dbg(p, _NORMAL_BLOCK); // 此处报错!!!
#else
free(p);
#endif
}请大侠们帮助!
解决方案 »
- 记录集对象如何定义成数组?
- 如何让程序一下子停下来
- 插入USB盘的时候电脑会自动弹出一个打开列表的窗口,询问要做什么,请问如何把我自己的程序加到这个列表中,用我的程序打开?
- ::LoadString() 的工作方式。
- 如何自动关闭对话框?
- 请各位大侠给小弟一点建议
- 有哪位能不能给我提供一个简单的用ODBC的数据库的例子?在线等待
- 机械的《MFC Visual C++ 6编程技术内幕》如何?我以为是《Visual C++技术内幕》而买了,有点上当的感觉。
- 求两向量超过180度的夹角
- 在asp中服务器段创建的com组件,如ADODB与下载到客户端执行的activex(如3721中文网址)有何不同
- 数据位置放的不同也错??请解释一下。
- Vc6 和 Vc3.0 有 何 区 别?
查一下。
http://www.csdn.net/Develop/article/22%5C22056.shtm
但我将参数改为void CapPic(CString strPicFileName)就没有问题了.CString g_strFileName = "1.bmp"是动态连接库中的全局变量, CapPic()是dll的使用程序.程序为DEBUG版本.????