问题程序如下,运行时,报错:ghgh.exe 中的 0x0042174f 处未处理的异常: 0xC0000005: 写入位置 0x00000000 时发生访问冲突。
以下是程序块,大家看看。红色部分是报错的地方。
inline void Histogram(CImage *pImg, int x, int y, int Dx, int Dy, long *pg)
{
struct IMAGEPARAMENT P;
int i, j;
BYTE *buf;
GetImageParament(pImg, &P); for (i = 0; i < 256; i++) pg[i] = 0; //MessageBox(NULL, _T("示例用法"), _T("demo"), MB_OK); for (i = 0; i < y + Dy; i++)
{
buf = (BYTE*) pImg->GetPixelAddress(0, i);
for (j = x; j < x + Dx; j++)
pg[buf[j]]++;
}
}
调用形式如下:void CghghView::OnHistog()
{
// TODO: 在此添加命令处理程序代码
long *pg = 0;
int x = 0, y = 0, s = 0, h = 0;
struct IMAGEPARAMENT P;
CClientDC dc(this); GetImageParament(pImg[1], &P);
Histogram(pImg[1], 0, 0, P.nWidth, P.nHeight, pg); //这样子调用,不会报错,当如果把pg改为*pg,编译就无法通过
CreateHistogram(pImg[2], pg, h, 0, 0);
pImg[2]->BitBlt (dc, x, y, s + 20, h + 20, 0, 0, SRCCOPY);}
大家帮忙指点下,先谢谢了
以下是程序块,大家看看。红色部分是报错的地方。
inline void Histogram(CImage *pImg, int x, int y, int Dx, int Dy, long *pg)
{
struct IMAGEPARAMENT P;
int i, j;
BYTE *buf;
GetImageParament(pImg, &P); for (i = 0; i < 256; i++) pg[i] = 0; //MessageBox(NULL, _T("示例用法"), _T("demo"), MB_OK); for (i = 0; i < y + Dy; i++)
{
buf = (BYTE*) pImg->GetPixelAddress(0, i);
for (j = x; j < x + Dx; j++)
pg[buf[j]]++;
}
}
调用形式如下:void CghghView::OnHistog()
{
// TODO: 在此添加命令处理程序代码
long *pg = 0;
int x = 0, y = 0, s = 0, h = 0;
struct IMAGEPARAMENT P;
CClientDC dc(this); GetImageParament(pImg[1], &P);
Histogram(pImg[1], 0, 0, P.nWidth, P.nHeight, pg); //这样子调用,不会报错,当如果把pg改为*pg,编译就无法通过
CreateHistogram(pImg[2], pg, h, 0, 0);
pImg[2]->BitBlt (dc, x, y, s + 20, h + 20, 0, 0, SRCCOPY);}
大家帮忙指点下,先谢谢了
解决方案 »
- 在对话框里里画图,大家帮忙解答一下
- 关闭Recordset出错
- 调用自定义的静态库时,是否必须包含头文件?如果不包含相应的头文件能否实现调用?
- 一个简单的问题
- MFC picture control控件问题
- 如何从数据库中读出指定数目的数据?
- 从资源管理器把文件或文件夹拖出来时,作为接收方的程序(已成功注册COleDropTarget)在OnDrop时如何得到此文件(最好是CFile *)
- 为什么用CStdioFile的ReadString读取文本,到其中的一行乱码(可能是unicode)就不能往下读了,怎么解决
- 一个很简单的语法问题
- 没有向导生成器如何生成带滚动的子窗口
- 请教高手:怎么实现clistbox实现(ctrl /shift)多选,然后返回选择项的索引信息
- 在OnEraseBkgnd里画背景,拉伸对话框窗口,发现铺上的位图闪烁厉害怎么解决??
2.代入参数改为*pg会编译不过,因为你的Histogram函数的参数就是一个long指针,代入的时候当然要代入指针pg,而不是*pg....
long *pg = 0; 指针没有地址空间.
引用时的时候会内存报错.
long *pg = new long[256];
最后记得delete[] pg;