我无法将任何消息输出到 Visual Studio 2012 中的输出窗口。
std::cout << "string"
上面的方法不起作用,因为没有内容发送到调试窗口。
但是我还发现了JUCE使用的一个DBG函数,即
DBG("message")
但这会产生相同的结果,没有消息发送到输出窗口。
我继续研究,最终发现我应该在Visual Studio中使用OutputDebugString函数进行调试,我在下面的代码中使用了它(看中间的初始化函数),
#include "../JuceLibraryCode/JuceHeader.h"
#include "Logn.h"
#include "C:\Users\User\Documents\Visual Studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\stdafx.h"
#include "Window.h"
#include <windows.h>
#include <iostream>
#include <fstream>
//==============================================================================
class MainWindow : public DocumentWindow
{
public:
MainWindow() : DocumentWindow ("JUCE Hello World!", Colours::lightgrey, DocumentWindow::allButtons,true)
{
setContentOwned(new Window(), true);
centreWithSize(getWidth(), getHeight());
setVisible(true);
}
~MainWindow()
{
}
void closeButtonPressed() override
{
JUCEApplication::quit();
}
};
class Test_1Application : public JUCEApplication
{
public:
//==============================================================================
Test_1Application() {}
const String getApplicationName() override { return ProjectInfo::projectName; }
const String getApplicationVersion() override { return ProjectInfo::versionString; }
bool moreThanOneInstanceAllowed() override { return true; }
//==============================================================================
void initialise (const String& commandLine) override
{
// Add your application's initialisation code here..
mainWindow = new MainWindow();
OutputDebugString("My output string.");
}
void shutdown() override
{
// Add your application's shutdown code here..
mainWindow = nullptr;
}
//==============================================================================
void systemRequestedQuit() override
{
// This is called when the app is being asked to quit: you can ignore this
// request and let the app carry on running, or call quit() to allow the app to close.
quit();
}
void anotherInstanceStarted (const String& commandLine) override
{
// When another instance of the app is launched while this one is running,
// this method is invoked, and the commandLine parameter tells you what
// the other instance's command-line arguments were.
}
private:
ScopedPointer<MainWindow> mainWindow;
};
//==============================================================================
// This macro generates the main() routine that launches the app.
START_JUCE_APPLICATION (Test_1Application)
但是,上面的方法也不起作用,并产生以下错误消息,
1>------ Build started: Project: NewProject, Configuration: Debug Win32 ------
1> Main.cpp
1>c:\users\user\programming\cpp\source\main.cpp(53): warning C4100: 'commandLine' : unreferenced formal parameter
1>c:\users\user\programming\cpp\source\main.cpp(78): warning C4100: 'commandLine' : unreferenced formal parameter
1>c:\users\user\programming\cpp\source\main.cpp(90): error C2731: 'WinMain' : function cannot be overloaded
1> c:\users\user\programming\cpp\source\main.cpp(90) : see declaration of 'WinMain'
1>c:\users\user\programming\cpp\source\main.cpp(90): error C2733: 'WinMain' : second C linkage of overloaded function not allowed
1> c:\program files (x86)\windows kits\8.0\include\um\winbase.h(2188) : see declaration of 'WinMain'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
我在没有使用 JUCE 的情况下启动了一个新项目,OutputDebugString 功能完美运行。
所以问题是 JUCE 框架不能很好地使用 OutputDebugString 函数,这似乎是我可以用来将任何内容输出到 Visual Studio 中的调试窗口的唯一函数。
请帮我弄清楚这一切应该如何运作以及我需要做什么来解决它。我对 C++、Visual Studio 和 JUCE 相当陌生,所以这是我需要修复的错误障碍。我想做的就是将 hello world 输出到输出窗口。 >:(
您似乎没有从 DBG 获得输出,因为程序未编译。尝试删除除 juce 之外的所有 #include。它也不会使用 outputDebugString 进行编译,除非您将其更改为...
Logger::outputDebugString("blah");
...但无论如何你都应该使用 DBG 宏(因为这些语句仅在调试版本中编译)。
多年来我一直在努力解决这个问题,但我刚刚在 Visual Studio 2022 中的输出窗口底部发现了一个选项卡,称为“立即窗口”。来自 JUCE DBG 的消息(“消息”)确实出现在那里。