我无法将任何消息输出到 Visual Studio 2012 中的输出窗口。
std::cout << "string"
以上不起作用,因为没有内容发送到调试窗口。
但是我也找到了JUCE使用的一个DBG函数,即
DBG("message")
但这会产生相同的结果,没有消息发送到输出窗口。
我继续研究,最终发现应该是在visual studio中使用OutputDebugString函数进行调试,我在下面的代码中使用了这个函数(看中间的initialise函数),
#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 输出到输出窗口。>:(