c++ 如何在VS 2012中使用Juce框架将内容发送到输出窗口

eyh26e7m  于 2023-06-25  发布在  其他
关注(0)|答案(2)|浏览(114)

我在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相当陌生,所以这对我来说是一个bug障碍。我所要做的就是将hello world输出到输出窗口。>:(

8yoxcaq7

8yoxcaq71#

看起来您没有从DBG获得输出,因为程序没有编译。尝试删除除了juce之外的所有#includes。它也不会用outputDebugString编译,除非你把它改成...

Logger::outputDebugString("blah");

...但无论如何都应该使用DBG宏(因为这些语句只在调试版本中编译)。

13z8s7eq

13z8s7eq2#

我也有同样的问题

DBG("message");

但事实证明,我点击的是“不带调试按钮启动”,而不是“本地Windows调试器按钮”。

当我使用本地Windows调试器按钮时,我所有的消息都显示在输出窗口中。

相关问题