gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 11:33:37 28 4
gpt4 key购买 nike

我在将任何消息输出到 Visual Studio 2012 中的输出窗口时遇到问题。

std::cout << "string" 

以上内容不起作用,因为没有内容发送到调试窗口。

但是我也找到了一个JUCE使用的DBG函数,即

DBG("message")

但这会产生相同的结果,没有消息发送到输出窗口。

我继续研究,最终发现我应该使用 OutputDebugString 函数在 visual studio 中进行调试,我在下面的代码中使用了该函数(查看中途的初始化函数),

#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 之外的所有#includes。它也不会使用 outputDebugString 进行编译,除非您将其更改为...

    Logger::outputDebugString("blah");

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

关于c++ - 我应该如何在 VS 2012 中使用 Juce 框架将内容发送到输出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23639165/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com