(200分)遇到了许多的奇怪问题,请高手们帮忙!!
BCB6+SQL Server
在修改了一个服务器程序之后出现了太多的奇怪问题,请高手们帮忙指点一下了
因为程序太长了,没办法在这里贴,请 高手 在分析分析这些奇怪的现象,看看
有可能是哪些原因造成的,给小D我指条解决的路,多谢了!!
1。在服务器启动之后需要加载一些配置参数,程序有两种方法解决,一种是通过读取在注册表中写入的信息参数,当这种情况失败的时候(例如注册表里没有写入这些参数),读取和程序同一目录下的ini配置文件,来加载这些配置参数。
2。奇怪的事情:在通过第一种方法加载这些参数后(我已经反复测试了,成功加载了,并且给参数结构体的赋值都是正确的),在初始化一些其他模块后程序出现了内存访问错误(就是平常常见的那种内存读写错误),比较奇怪的是无论我怎么跟断点都跟不到这个错误,并且关闭了所有程序启动时new出的线程。
3。更奇怪的事情:我反复调试后找不到错误,只好调用前几天的版本,这些版本在前些调试时都是通过读取ini文件来配置参数的(没有其他问题),今天通过读注册表时在编译条件成功运行,但是一旦我脱离了编译环境,程序就出现了内存访问的错误,就和今天的版本(在编译条件下也有内存访问的错)出现了一样的错误。
4。所有这些奇怪的问题都只出现在通过注册表读取配置信息的时候。
而通过注册表和ini 文件读取配置信息的函数是完全相同的条件下调用。
5。简单的说一下程序的初始化的流程
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
ThreadCount = 0;
//check for the existence of the mutex.
HANDLE Mutex = OpenMutex(MUTEX_ALL_ACCESS, false, "OneInstanceAllowed ");
if (Mutex == NULL)//this is the only instance
{
//create the mutex...
Mutex = CreateMutex(NULL, true, "OneInstanceAllowed ");
}
else //this is not the only instance
{
//Send a message to the previous instance of the application, asking
//it to restore and front itself.
SendMessage(HWND_BROADCAST, RegisterWindowMessage("OnlyOne "), 0, 0);
MessageDlg("对不起,您不能同时启动两个服务器程序!当前程序将自动退出!", mtError, TMsgDlgButtons()<<mbOK, 0);
return 0;
}
Application->Initialize();
//Let the application run normally...
frmLog = new TfrmLog(Application);
frmLog->Show();
frmLog->Update();
frmLog->StartGauge->Visible = true;
frmLog->LblProgress->Caption = "正载初始化系统...";
Application->ProcessMessages();
if(FindWindow(NULL,"Smart Agent")==NULL)
WinExec("osagent.exe",0);
//以下三行设置Hint提示样式
Application->HintColor = clYellow;
Application->HintHidePause = 10000;
Application->HintPause = 0;
frmLog->LblProgress->Caption = "正载启动数据模块...";
frmLog->StartGauge->Progress = 5;
Application->ProcessMessages();
AnsiString DBIniFile = ExtractFilePath(Application->ExeName)+"ServerInfo.ini";
AnsiString DefParamFile = ExtractFilePath(Application->ExeName)+"DefParam.ini";
SystemDModule = new TDModule(DBIniFile,DefParamFile);
frmLog->LblProgress->Caption = "正载启动调度模块...";
frmLog->StartGauge->Progress += 5;
Application->ProcessMessages();
SystemManager = new TManagerCenter(SystemDModule->PlantNums);
SystemManager->DModule = SystemDModule;
//在这个设置调度模块的数据模块时读取配置参数
SystemDModule->ManagerCenter = SystemManager;
frmLog->LblProgress->Caption = "正载启动Socket模块...";
frmLog->StartGauge->Progress += 5;
Application->ProcessMessages();
SystemSocket = new TSocketModule(SystemDModule->PlantNums,Application);
SystemSocket->sManager = SystemManager;
SystemManager->SocketModule = SystemSocket;
frmLog->LblProgress->Caption = "正载启动Corba......";
frmLog->StartGauge->Progress += 10;
Application->ProcessMessages();
// Initialize the ORB and BOA
orb = CORBA::ORB_init(__argc, __argv);
boa = orb->BOA_init(__argc, __argv);
RemoteServerImpl remoteServer_RemoteServerObject("RemoteServerObject");
boa->obj_is_ready(&remoteServer_RemoteServerObject);
//跟断点的时候是在CORBA初始化后出现了内存访问的错误
//但应该不是CORBA的问题,毕竟读取ini文件的情况没错
//这之后也程序也就过不去了
frmLog->LblProgress->Caption = "正载启动主窗体......";
frmLog->StartGauge->Progress += 20;
Application->ProcessMessages();
Application->Title = "服务器";
Application->CreateForm(__classid(TfrmMain), &frmMain);
frmLog->StartGauge->Progress += 10;
Sleep((unsigned int)1000);
delete frmLog;
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
return 0;
}
//---------------------------------------------------------------------------
请各位大虾们,帮我看看,可能会是哪些原因出现了这些错误,我都快要崩溃了:(
btw:不知道为什么我不能给200分,等问题解决后一定开贴送分!!