我正在使用C#和Visual Studio 2010.
当我OutputDebugString用来编写调试信息时,它应该出现在输出窗口中吗?
我可以OutputDebugString在DebugView中看到输出,但我想我会在Visual Studio的Output窗口中看到它.我看过菜单工具?选项?调试?常规,输出未被重定向到立即窗口.我也看了菜单工具*?选项?调试?输出窗口和所有常规输出设置都设置为"开".最后,我使用了Output窗口中的下拉列表来指定应该出现Debug消息.
如果我更改菜单工具*?选项?调试?一般将输出重定向到立即窗口,OutputDebugString消息不会出现在即时窗口中.
这是我的整个测试程序:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace OutputDebugString
{
class Program
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern void OutputDebugString(string message);
static void Main(string[] args)
{
Console.WriteLine("Main - Enter - Console.WriteLine");
Debug.WriteLine("Main - Enter - Debug.WriteLine");
OutputDebugString("Main …Run Code Online (Sandbox Code Playgroud) 是
OutputDebugString(PAnsiChar(''));
Run Code Online (Sandbox Code Playgroud)
线程安全?
我/我们一直在线程中使用它来进行调试,如果我以不同的方式做这件事我就不会想到它.
(德尔福7)
我正在尝试使用以下代码捕获所有OutputDebugString消息(包括来自服务的消息).它运行正常,直到我迁移到Windows 7.
问题是,由于Windows Vista服务在低级别的Session#0中运行,有些人说它不可能捕获它们,有些人认为它是不可能的.你怎么看?
是否可以通过增加一些权限来修改以下代码,以便能够从Session#0 接收OutputDebugString消息?换一种说法; 是否可以在会话#0中与会话#0共享DBWIN_BUFFER?
我想它应该是可能的,因为例如DebugView可以做到这一点,我看不到任何服务助手,它会将这些消息(例如通过命名管道)从Session#0发送到GUI#1运行的会话#1.
问题将是安全设置中的IMO.任何人都可以建议我如何修改它们?
type
TODSThread = class(TThread)
protected
procedure Execute; override;
end;
...
procedure TODSThread.Execute;
var SharedMem: Pointer;
SharedFile: THandle;
WaitingResult: DWORD;
SharedMessage: string;
DataReadyEvent: THandle;
BufferReadyEvent: THandle;
SecurityAttributes: SECURITY_ATTRIBUTES;
SecurityDescriptor: SECURITY_DESCRIPTOR;
begin
SecurityAttributes.nLength := SizeOf(SECURITY_ATTRIBUTES);
SecurityAttributes.bInheritHandle := True;
SecurityAttributes.lpSecurityDescriptor := @SecurityDescriptor;
if not InitializeSecurityDescriptor(@SecurityDescriptor, SECURITY_DESCRIPTOR_REVISION) then
Exit;
if not SetSecurityDescriptorDacl(@SecurityDescriptor, True, nil, False) then
Exit;
BufferReadyEvent := CreateEvent(@SecurityAttributes, False, True, 'DBWIN_BUFFER_READY');
if BufferReadyEvent = 0 …Run Code Online (Sandbox Code Playgroud) c# delphi windows-services remote-debugging outputdebugstring
我想OutputDebugString()在我的应用程序中使用,然后可以选择在现场部署应用程序时在单独的查看器中显示它.
也就是说,我不想更改标志并重建我的.exe来打开和关闭调试.
谷歌搜索,似乎DebugView应该处理,但它和TraceTool都没有显示此代码的任何输出.
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
OutputDebugString(PChar('Hello, wurld'));
end;
end.
Run Code Online (Sandbox Code Playgroud)
我已阅读文档但无济于事,并看到其他人遇到过类似的问题,但尚未发布解决方案.
有解决方案吗?
这种情况不止一次发生在我身上,导致许多人失去了追逐幽灵的时间.通常,当我调试一些非常困难的与时序相关的代码时,我开始添加大量的OutputDebugString()调用,因此我可以很好地了解相关操作的顺序.问题是,Delphi 6 IDE似乎只能处理这种情况这么久.我将使用一个具体的例子,我只是为了避免一般性(尽可能多).
我花了几天时间调试我的线程间信号量锁定代码以及我的DirectShow时间戳计算代码,这导致了一些非常令人沮丧的问题.在消除了我能想到的每一个错误之后,我仍然遇到了Skype的问题,我的应用程序发送了音频.
大约10秒钟之后,我在谈话和听到我的声音之间的延迟来自于我用于测试的第二台PC上的Skype,呼叫的远端开始增长.在大约20-30秒时,延迟开始呈指数级增长,此时触发的代码我检查了一个关键部分是否持有时间过长.
幸运的是,它并没有太晚,并且在此之前经历过这一切,我决定停止无情地跟踪并关闭大部分的OutputDebugString().值得庆幸的是,我将大部分内容包装在条件编译器定义中,因此很容易做到.我这样做的那一刻问题消失了,事实证明我的代码工作正常.
因此,当OutputDebugstring()流量超过某个阈值时,看起来Delphi 6 IDE开始陷入困境.也许只是向事件日志调试器窗格添加字符串的任务,该窗格包含所有OutputDebugString()报告.我不知道,但是当TMemo或类似控件开始包含太多字符串时,我在应用程序中看到了类似的问题.
那些人为了防止这种情况做了什么?有没有办法通过某种方法调用清除事件日志或至少是限制其大小的方法?此外,您通过条件定义,IDE插件或其他什么技术来应对这种情况?
我的程序适用于windows xp.我试图添加一些更多的功能,并OutputDebugString()用于显示一些调试信息.在XP上完美运行.现在我想在Windows 7x64上使用相同的程序.我没有看到任何输出DebugView.
F1! F1! F1!
我正在使用使用该函数的第三方库,OutputDebugString()在阅读 MSDN 文档时,它似乎表明这是用于打印到调试器。
但这对我来说很不方便,如果没有连接调试器,有没有办法读取这个输出?
如果它是我的 LIB,我希望在用户通过--debug或类似时将输出转到 stdout/stderr ,但由于它不是我正在寻找其他方法将此信息传递到控制台(或文件)而不连接调试器。
我在我的Delphi代码中使用OutputDebugString,但是我收到错误:
错误:未声明的标识符:'OutputDebugString'
这个OutputDebugString是哪个包?
我在我的应用程序中有一些"流氓"OutputDebugString调用打印出"T",但我无法找到它.
是否有可能以某种方式在OutputDebugString -function上设置断点并查看它的调用位置?
我正在使用Delphi 2009.
Delphi OSX单元中是否有NSLog声明.我没能在Firemonkey应用程序中找到OutputDebugString的替代品.
最终解决方案如下所示:
/// <remarks>
/// Output debug string. Output debug string can be seen in Delphi
/// View|Debug Windows|Event Log or with 3-rd party programs such as
/// dbgview.exe from SysInternals (www.sysinternals.com)
/// </remarks>
procedure ODS(const Text: string);
begin
{$IFDEF MACOS}
// http://stackoverflow.com/questions/12405447/outputdebugstring-with-delphi-for-macosunit unt_Debug;
Log.d(Text);
{$ENDIF}
{$IFDEF LINUX}
__write(stderr, AText, Length(AText));
__write(stderr, EOL, Length(EOL));
{$ENDIF}
{$IFDEF MSWINDOWS}
OutputDebugString(PWideChar(Text));
{$ENDIF}
end;
Run Code Online (Sandbox Code Playgroud) delphi ×7
debugging ×4
c# ×2
breakpoints ×1
c ×1
c++ ×1
capture ×1
debugview ×1
delphi-2009 ×1
delphi-7 ×1
delphi-xe2 ×1
firemonkey ×1
logging ×1
nslog ×1
windows ×1