-
c语言入门之在BCB下使用GExperts的Debug功能
GExperts是BCB的一个插件,其中有一项功能是Debug,非常好用。但是由于定义它的是pas文件(这个文件是GExperts安装目录下DbugIntf.pas),所以不能在BCB中直接使用。我把这个文件转换成C++文件,但是使用的时候注意把dbugintf.h文件copy到工程所在的目录中,直接在文件中用#include引用,不要添加到project中!
具体的使用方法还是看帮助吧!下面是转换后的文件。
/*-----------------------------------------------------------------------------
Unit Name: dbugintf.h
Author: yuanhen
Email: yuanhen88@hotmail.com
yuanhen88@mail.china.com
Purpose: translate Delphi version to C++Builder's
Date: 2003/06/05
Time: 20:42:08
History:
NOTE NOTE NOTE:
DON'T ADD this file to your project. Otherwise, this file should be include
to your project manually
-----------------------------------------------------------------------------*/
#ifndef DBUGINTF_H
#define DBUGINTF_H
#ifdef LINUX
#include <iostream>
#endif LINUX
#include <vcl.h>
#include <Registry.hpp>
//---------------------------------------------------------------------------
// global variables
AnsiString MsgPrefix;
const char chrClearCommand = 3;
bool PastFailedAttemptToStartDebugWin = false;
const AnsiString Indentation = " ";
// declaration
void SendBoolean(const AnsiString &Identifier, const bool Value);
void SendDateTime(const AnsiString &Identifier, const TDateTime Value);
void SendDebugEx(const AnsiString &Msg, TMsgDlgType MType);
void SendDebug(const AnsiString &Msg);
void SendDebugClear();
void SendInteger(const AnsiString &Identifier, const int Value);
void SendMethodEnter(const AnsiString &MethodName);
void SendMethodExit(const AnsiString &MethodName);
void SendSeparator();
void SendDebugFmt(const AnsiString &Msg, const TVarRec *Args);
void SendDebugFmtEx(const AnsiString &Msg, const TVarRec *Args, TMsgDlgType MType);
HWND StartDebugWin();
// definition
void SendBoolean(const AnsiString &Identifier, const bool Value)
{
// Note: We deliberately leave "True" and "False" as
// hard-coded string constants, since these are
// technical terminology which should not be localised.
if (Value)
SendDebugEx(Identifier + "= True", mtInformation);
else
SendDebugEx(Identifier + "= False", mtInformation);
}
void SendDateTime(const AnsiString &Identifier, const TDateTime Value)
{
SendDebugEx(Identifier + '=' + DateTimeToStr(Value), mtInformation);
}
void SendDebugEx(const AnsiString &Msg, TMsgDlgType MType)
{
TCopyDataStruct CDS;
HWND DebugWin;
AnsiString MessageString;
#ifdef LINUX
const AnsiString MTypeStr[TMsgDlgType] =
{"Warning: ", "Error: ", "Information: ", "Confirmation: ", "Custom: "};
#endif LINUX
#ifdef LINUX
std::cout << "GX: " << MTypeStr[MType] << Msg << std::endl;
#endif LINUX
#ifndef LINUX
DebugWin = FindWindow("TfmDebug", NULL);
if (DebugWin == 0)
DebugWin = StartDebugWin();
if (DebugWin != 0)
{
MessageString = MsgPrefix + Msg;
CDS.cbData = MessageString.Length() + 4;
CDS.dwData = 0;
AnsiString com;
if (Msg == chrClearCommand)
{
com = chrClearCommand;
com += AnsiString(MType + 1) + MessageString;
com += '\0';
}
else
{
com = '\1';
com = com + AnsiString(MType + 1) + MessageString;
com = com + '\0';
}
CDS.lpData = com.c_str();
SendMessage(DebugWin, WM_COPYDATA, WPARAM(Application->Handle), LPARAM(&CDS));
}
#endif LINUX
}
void SendDebug(const AnsiString &Msg)
{
SendDebugEx(Msg, mtInformation);
}
void SendDebugClear()
{
SendDebug(chrClearCommand);
}
void SendInteger(const AnsiString &Identifier, const int Value)
{
SendDebugEx(AnsiString(Identifier + " = " + Value), mtInformation);
}
void SendMethodEnter(const AnsiString &MethodName)
{
MsgPrefix = MsgPrefix + Indentation;
SendDebugEx("Entering " + MethodName, mtInformation);
}
void SendMethodExit(const AnsiString &MethodName)
{
SendDebugEx("Exiting " + MethodName, mtInformation);
MsgPrefix.Delete(1, Indentation.Length());
}
void SendSeparator()
{
const AnsiString SeparatorString = "------------------------------";
SendDebugEx(SeparatorString, mtInformation);
}
void SendDebugFmt(const AnsiString &Msg, const TVarRec *Args)
{
SendDebugEx(Msg.Format(Msg, Args, sizeof(Args)), mtInformation);
}
void SendDebugFmtEx(const AnsiString &Msg, const TVarRec *Args, TMsgDlgType MType)
{
SendDebugEx(Msg.Format(Msg, Args, sizeof(Args)), MType);
}
HWND StartDebugWin()
{
AnsiString DebugFilename;
char Buf[MAX_PATH + 1];
TStartupInfo si;
TProcessInformation pi;
MsgPrefix = "";
HWND Result = 0;
if (PastFailedAttemptToStartDebugWin)
exit;
TRegIniFile *File = new TRegIniFile("\\Software\\GExperts");
__try
{
DebugFilename = File->ReadString("Debug", "FilePath", "");
}
__finally
{
delete File;
}
if (DebugFilename.Trim() == "")
{
GetModuleFileName(NULL, Buf, sizeof(Buf)-1);
DebugFilename = ExtractFilePath(StrPas(Buf))+"GDebug.exe";
}
if (DebugFilename.Trim() == "" || (!FileExists(DebugFilename)))
{
PastFailedAttemptToStartDebugWin = true;
exit;
}
memset(&si, '\0', sizeof(si));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOW;
if (!CreateProcess(DebugFilename.c_str(), NULL,
NULL, NULL,
false, 0, NULL, NULL,
&si, &pi))
{
PastFailedAttemptToStartDebugWin = true;
exit;
}
__try
{
WaitForInputIdle(pi.hProcess, 3000); // wait for 3 seconds to get idle
}
__finally
{
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}
Result = FindWindow("TfmDebug", NULL);
return Result;
}
#endif DBUGINTF_H
具体的使用方法还是看帮助吧!下面是转换后的文件。
/*-----------------------------------------------------------------------------
Unit Name: dbugintf.h
Author: yuanhen
Email: yuanhen88@hotmail.com
yuanhen88@mail.china.com
Purpose: translate Delphi version to C++Builder's
Date: 2003/06/05
Time: 20:42:08
History:
NOTE NOTE NOTE:
DON'T ADD this file to your project. Otherwise, this file should be include
to your project manually
-----------------------------------------------------------------------------*/
#ifndef DBUGINTF_H
#define DBUGINTF_H
#ifdef LINUX
#include <iostream>
#endif LINUX
#include <vcl.h>
#include <Registry.hpp>
//---------------------------------------------------------------------------
// global variables
AnsiString MsgPrefix;
const char chrClearCommand = 3;
bool PastFailedAttemptToStartDebugWin = false;
const AnsiString Indentation = " ";
// declaration
void SendBoolean(const AnsiString &Identifier, const bool Value);
void SendDateTime(const AnsiString &Identifier, const TDateTime Value);
void SendDebugEx(const AnsiString &Msg, TMsgDlgType MType);
void SendDebug(const AnsiString &Msg);
void SendDebugClear();
void SendInteger(const AnsiString &Identifier, const int Value);
void SendMethodEnter(const AnsiString &MethodName);
void SendMethodExit(const AnsiString &MethodName);
void SendSeparator();
void SendDebugFmt(const AnsiString &Msg, const TVarRec *Args);
void SendDebugFmtEx(const AnsiString &Msg, const TVarRec *Args, TMsgDlgType MType);
HWND StartDebugWin();
// definition
void SendBoolean(const AnsiString &Identifier, const bool Value)
{
// Note: We deliberately leave "True" and "False" as
// hard-coded string constants, since these are
// technical terminology which should not be localised.
if (Value)
SendDebugEx(Identifier + "= True", mtInformation);
else
SendDebugEx(Identifier + "= False", mtInformation);
}
void SendDateTime(const AnsiString &Identifier, const TDateTime Value)
{
SendDebugEx(Identifier + '=' + DateTimeToStr(Value), mtInformation);
}
void SendDebugEx(const AnsiString &Msg, TMsgDlgType MType)
{
TCopyDataStruct CDS;
HWND DebugWin;
AnsiString MessageString;
#ifdef LINUX
const AnsiString MTypeStr[TMsgDlgType] =
{"Warning: ", "Error: ", "Information: ", "Confirmation: ", "Custom: "};
#endif LINUX
#ifdef LINUX
std::cout << "GX: " << MTypeStr[MType] << Msg << std::endl;
#endif LINUX
#ifndef LINUX
DebugWin = FindWindow("TfmDebug", NULL);
if (DebugWin == 0)
DebugWin = StartDebugWin();
if (DebugWin != 0)
{
MessageString = MsgPrefix + Msg;
CDS.cbData = MessageString.Length() + 4;
CDS.dwData = 0;
AnsiString com;
if (Msg == chrClearCommand)
{
com = chrClearCommand;
com += AnsiString(MType + 1) + MessageString;
com += '\0';
}
else
{
com = '\1';
com = com + AnsiString(MType + 1) + MessageString;
com = com + '\0';
}
CDS.lpData = com.c_str();
SendMessage(DebugWin, WM_COPYDATA, WPARAM(Application->Handle), LPARAM(&CDS));
}
#endif LINUX
}
void SendDebug(const AnsiString &Msg)
{
SendDebugEx(Msg, mtInformation);
}
void SendDebugClear()
{
SendDebug(chrClearCommand);
}
void SendInteger(const AnsiString &Identifier, const int Value)
{
SendDebugEx(AnsiString(Identifier + " = " + Value), mtInformation);
}
void SendMethodEnter(const AnsiString &MethodName)
{
MsgPrefix = MsgPrefix + Indentation;
SendDebugEx("Entering " + MethodName, mtInformation);
}
void SendMethodExit(const AnsiString &MethodName)
{
SendDebugEx("Exiting " + MethodName, mtInformation);
MsgPrefix.Delete(1, Indentation.Length());
}
void SendSeparator()
{
const AnsiString SeparatorString = "------------------------------";
SendDebugEx(SeparatorString, mtInformation);
}
void SendDebugFmt(const AnsiString &Msg, const TVarRec *Args)
{
SendDebugEx(Msg.Format(Msg, Args, sizeof(Args)), mtInformation);
}
void SendDebugFmtEx(const AnsiString &Msg, const TVarRec *Args, TMsgDlgType MType)
{
SendDebugEx(Msg.Format(Msg, Args, sizeof(Args)), MType);
}
HWND StartDebugWin()
{
AnsiString DebugFilename;
char Buf[MAX_PATH + 1];
TStartupInfo si;
TProcessInformation pi;
MsgPrefix = "";
HWND Result = 0;
if (PastFailedAttemptToStartDebugWin)
exit;
TRegIniFile *File = new TRegIniFile("\\Software\\GExperts");
__try
{
DebugFilename = File->ReadString("Debug", "FilePath", "");
}
__finally
{
delete File;
}
if (DebugFilename.Trim() == "")
{
GetModuleFileName(NULL, Buf, sizeof(Buf)-1);
DebugFilename = ExtractFilePath(StrPas(Buf))+"GDebug.exe";
}
if (DebugFilename.Trim() == "" || (!FileExists(DebugFilename)))
{
PastFailedAttemptToStartDebugWin = true;
exit;
}
memset(&si, '\0', sizeof(si));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOW;
if (!CreateProcess(DebugFilename.c_str(), NULL,
NULL, NULL,
false, 0, NULL, NULL,
&si, &pi))
{
PastFailedAttemptToStartDebugWin = true;
exit;
}
__try
{
WaitForInputIdle(pi.hProcess, 3000); // wait for 3 seconds to get idle
}
__finally
{
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}
Result = FindWindow("TfmDebug", NULL);
return Result;
}
#endif DBUGINTF_H
最新更新
Objective-C语法之代码块(block)的使用
VB.NET eBook
Add-in and Automation Development In VB.NET 2003 (F
Add-in and Automation Development In VB.NET 2003 (8
Add-in and Automation Development in VB.NET 2003 (6
Add-in and Automation Development In VB.NET 2003 (5
AddIn Automation Development In VB.NET 2003 (4)
AddIn And Automation Development In VB.NET 2003 (2)
Addin and Automation Development In VB.NET 2003 (3)
AddIn And Automation Development In VB.NET 2003 (1)
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
SQL Server -- 解决存储过程传入参数作为s
武装你的WEBAPI-OData入门
武装你的WEBAPI-OData便捷查询
武装你的WEBAPI-OData分页查询
武装你的WEBAPI-OData资源更新Delta
5. 武装你的WEBAPI-OData使用Endpoint 05-09
武装你的WEBAPI-OData之API版本管理
武装你的WEBAPI-OData常见问题
武装你的WEBAPI-OData聚合查询
OData WebAPI实践-OData与EDM
OData WebAPI实践-Non-EDM模式