c++ builder:在windows .cpp中访问冲突0x0000002c

C++-builder: access violation 0x0000002c in window.cpp

本文关键字:访问冲突 0x0000002c cpp windows builder c++      更新时间:2023-10-16

我正在修改c++ Builder XE2中的程序。该程序还不使用vcl,但使用owlnext。并包含多个MDI-child-forms。

在这里,我使用了一个例程来加载一个文件并打开一个新窗口。

在这个例程中一切工作正常(我在调试模式下一行接一行地跟踪它多次),但是当它完成并且PumpWaitingMessages() // pumps any waiting messages, idleCount=0再次完成并且TApplication::MessageLoop()进入下一个循环并调用IdleAction(idleCount++)调用MainWindow->IdleAction(idleCount)调用TWindow::IdleAction(idleCount)这是window.h的函数时,程序崩溃。

在IdleAction中,当调用win->IdleAction(idleCount)时,应用程序在第一个循环中崩溃,异常:

First chance exception at $004E4CA4. Exception class $C0000005 with message 'access violation at 0x004e4ca4: read of address 0x0000002c'. Process Project2.exe (3772)

函数在Owlnext中定义如下:

//
/// Called when no messages are waiting to be processed, IdleAction performs idle
/// processing as long as true is returned. idleCount specifies the number of times
/// idleAction has been called between messages.
///
/// Propagate idle action to all children if count==0, and to any children that
/// previously said they wanted more time.
//
bool
TWindow::IdleAction(long idleCount)
{
  bool wantMore = false;
  TWindow* win = GetFirstChild();
  if (win) {
    do {
      if (idleCount == 0 || win->IsFlagSet(wfPropagateIdle)) {
        if (win->IdleAction(idleCount)) {
          win->SetFlag(wfPropagateIdle);
          wantMore = true;
        }
        else {
          win->ClearFlag(wfPropagateIdle);
        }
      }
      win = win->Next();
    } while (win && win != GetFirstChild());
  }
  return wantMore;
}

我的猜测是,有一个无效的句柄的窗口,但win-object似乎并没有无效…我也找不到任何包含0x0000002c地址的变量。

标题和父级为NULL, Handle为0x00000004,但其他值对我来说似乎是合法的…奇怪的是,当检查cursormodule.name时,它告诉我E2122 Function call terminated by unhandled exception 0xc0000005 at address 0x408b1a

那么,有人知道为什么这个错误发生或者我可以做什么或撤消使它正常工作吗?

编辑:Win ->next是定义为

的owl函数
//
/// Returns a pointer to the next sibling window in the window's sibling list.
inline TWindow* TWindow::Next()
{
  return SiblingList;
}

设置TWindow* SiblingList;为windows的私有值windows是这样声明的:http://pastebin.com/TzTp4ZXh

你可以检查你是否正确设置了项目设置:有一个整数大小的枚举选项,必须打开结构对齐必须与OWLNext相同——默认为8字节。

另外,您是否可以在启用CodeGuard的情况下构建并查看它是否报告任何问题?

Jogy

所以,我仍然不太清楚这个问题是如何解决的,但由于我计划将其分段移植到vcl,所以我在主文件中加载了#include <vcl.h>

我还用owl::TFileSaveDialog(NULL, fileNameData))替换了所有的TFileSaveDialog(handle, fileNameData))

不,没有任何问题了。