c++ /c 混乱

发布于 2024-09-06 00:33:56 字数 6011 浏览 6 评论 0原文

我正在尝试用 C++ 制作一个小应用程序,用这个库保存 midifiles。 http://musicnote.sourceforge.net/docs/html/index.html

主页上给出的示例代码如下所示。

 #include "MusicNoteLib.h"
    void main()
    {
        MusicNoteLib::Player player; // Create the Player Object
        player.Play("C D E F G A B"); // Play the Music Notes on the default MIDI output port
    }

这段代码无法在 Visual studio 2008 中编译,我收到很多错误,例如

MusicNoteLib.h(22):错误 C4430: 缺少类型说明符 - 假定为 int。 注意:C++ 不支持default-int

我不明白这个错误或从哪里开始寻找...... 还有一些 dll 文件可以用来代替这个 h 文件。

    #ifndef __MUSICNOTE_LIB_H__EBEE094C_FF6E_43a1_A6CE_D619564F9C6A__
#define __MUSICNOTE_LIB_H__EBEE094C_FF6E_43a1_A6CE_D619564F9C6A__

/** @file MusicNoteLib.h
 * \brief Main header file for accessing the MusicNote Library
 */ 

/// <Summary>
/// This header file can be included directly in your project or through
/// MusicNoteLib.h of the MusicNoteDll project. If included directly, this
/// will be built directly as a satic library. If included through MusicNoteDll
/// this will use dllImports through MUSICNOTELIB_API
/// </Summary>
#ifndef MUSICNOTELIB_API
#define MUSICNOTELIB_API
#endif // MUSICNOTELIB_API

//#include "Player.h"

namespace MusicNoteLib /// Music Programming Library
{
typedef  void (__stdcall *LPFNTRACEPROC)(void* pUserData, const TCHAR* szTraceMsg);
typedef  void (__stdcall *LPFNERRORPROC)(void* pUserData, long lErrCode, const TCHAR* szErrorMsg, const TCHAR* szToken);

extern "C"
{
    MUSICNOTELIB_API typedef void MStringPlayer;

    MUSICNOTELIB_API void* GetCarnaticMusicNoteReader();

    /// <Summary>
    /// Creates a MusicString Player object.
    /// </Summary>
    MUSICNOTELIB_API MStringPlayer* CreateMusicStringPlayer();

    /// <Summary>
    /// Plays Music string notes on the default MIDI Output device with the default Timer Resolution.
    /// Use PlayMusicStringWithOpts() to use custom values.
    /// @param szMusicNotes the Music string to be played on the MIDI output device
    /// @return True if the notes were played successfully, False otherwise
    /// </Summary>
    MUSICNOTELIB_API bool PlayMusicString(const TCHAR* szMusicNotes);

    /// <Summary>
    /// Same as PlayMusicString() except that this method accepts Callbacks.
    /// The Trace and Error callbacks will be used during the Parse of the Music Notes.
    /// @param szMusicNotes the Music string to be played on the MIDI output device
    /// @param traceCallbackProc the Callback to used to report Trace messages
    /// @param errorCallbackProc the Callback to used to report Error messages
    /// @param pUserData any user supplied data that should be sent to the Callback
    /// @return True if the notes were played successfully, False otherwise
    /// </Summary>
    MUSICNOTELIB_API bool PlayMusicStringCB(const TCHAR* szMusicNotes,
                                            LPFNTRACEPROC traceCallbackProc, 
                                            LPFNERRORPROC errorCallbackProc, 
                                            void* pUserData);

    /// <Summary>
    /// Plays Music string notes on the given MIDI Output device using the given Timer Resolution.
    /// Use PlayMusicString() to use default values.
    /// @param szMusicNotes the Music notes to be played
    /// @param nMidiOutPortID the device ID of the MIDI output port to be used for the play
    /// @param nTimerResMS preferred MIDI timer resolution, in MilliSeconds
    /// @return True if Play was successful, False otherwise
    /// </Summary>
    MUSICNOTELIB_API bool PlayMusicStringWithOpts(const TCHAR* szMusicNotes, int nMidiOutPortID, unsigned int nTimerResMS);

    /// <Summary>
    /// Same as PlayMusicStringWithOpts() except that this method accepts Callbacks.
    /// The Trace and Error callbacks will be used during the Parse of the Music Notes.
    /// @param szMusicNotes the Music notes to be played
    /// @param nMidiOutPortID the device ID of the MIDI output port to be used for the play
    /// @param nTimerResMS preferred MIDI timer resolution, in MilliSeconds
    /// @param traceCallbackProc the Callback to used to report Trace messages
    /// @param errorCallbackProc the Callback to used to report Error messages
    /// @param pUserData any user supplied data that should be sent to the Callback
    /// @return True if Play was successful, False otherwise
    /// </Summary>
    MUSICNOTELIB_API bool PlayMusicStringWithOptsCB(const TCHAR* szMusicNotes, 
                                                    int nMidiOutPortID, 
                                                    unsigned int nTimerResMS,
                                                    LPFNTRACEPROC traceCallbackProc, 
                                                    LPFNERRORPROC errorCallbackProc, 
                                                    void* pUserData);
    /// <Summary>
    /// Save the given MusicString content into a MIDI output file
    /// @param szMusicNotes Music Notes to be converted to MIDI output
    /// @param szOutputFilePath path of the MIDI output file
    /// @return True if the the content was saved successfully, False otherwise
    /// </Summary>
    MUSICNOTELIB_API bool SaveAsMidiFile(const TCHAR* szMusicNotes, const char* szOutputFilePath);

    //MUSICNOTELIB_API typedef void (*ParseErrorProc)(const MusicNoteLib::CParser*, MusicNoteLib::CParser::ErrorEventHandlerArgs* pEvArgs);
    //MUSICNOTELIB_API typedef void (*ParseTraceProc)(const MusicNoteLib::CParser*, MusicNoteLib::CParser::TraceEventHandlerArgs* pEvArgs);

    MUSICNOTELIB_API void Parse(const TCHAR* szNotes, LPFNTRACEPROC traceCallbackProc, void* pUserData);

} // extern "C"



} // namespace MusicNoteLib

#endif // __MUSICNOTE_LIB_H__EBEE094C_FF6E_43a1_A6CE_D619564F9C6A__

Im trying to make a small app in c++ that saves midifiles with this library.
http://musicnote.sourceforge.net/docs/html/index.html

The sample code that is given on the homepage looks like this.

 #include "MusicNoteLib.h"
    void main()
    {
        MusicNoteLib::Player player; // Create the Player Object
        player.Play("C D E F G A B"); // Play the Music Notes on the default MIDI output port
    }

This piece of code won't compile in Visual studio 2008, I get many errors like

MusicNoteLib.h(22) : error C4430:
missing type specifier - int assumed.
Note: C++ does not support default-int

I don't understand the error or where to start looking...
There also was some dll files that can be used instead of this h file.

    #ifndef __MUSICNOTE_LIB_H__EBEE094C_FF6E_43a1_A6CE_D619564F9C6A__
#define __MUSICNOTE_LIB_H__EBEE094C_FF6E_43a1_A6CE_D619564F9C6A__

/** @file MusicNoteLib.h
 * \brief Main header file for accessing the MusicNote Library
 */ 

/// <Summary>
/// This header file can be included directly in your project or through
/// MusicNoteLib.h of the MusicNoteDll project. If included directly, this
/// will be built directly as a satic library. If included through MusicNoteDll
/// this will use dllImports through MUSICNOTELIB_API
/// </Summary>
#ifndef MUSICNOTELIB_API
#define MUSICNOTELIB_API
#endif // MUSICNOTELIB_API

//#include "Player.h"

namespace MusicNoteLib /// Music Programming Library
{
typedef  void (__stdcall *LPFNTRACEPROC)(void* pUserData, const TCHAR* szTraceMsg);
typedef  void (__stdcall *LPFNERRORPROC)(void* pUserData, long lErrCode, const TCHAR* szErrorMsg, const TCHAR* szToken);

extern "C"
{
    MUSICNOTELIB_API typedef void MStringPlayer;

    MUSICNOTELIB_API void* GetCarnaticMusicNoteReader();

    /// <Summary>
    /// Creates a MusicString Player object.
    /// </Summary>
    MUSICNOTELIB_API MStringPlayer* CreateMusicStringPlayer();

    /// <Summary>
    /// Plays Music string notes on the default MIDI Output device with the default Timer Resolution.
    /// Use PlayMusicStringWithOpts() to use custom values.
    /// @param szMusicNotes the Music string to be played on the MIDI output device
    /// @return True if the notes were played successfully, False otherwise
    /// </Summary>
    MUSICNOTELIB_API bool PlayMusicString(const TCHAR* szMusicNotes);

    /// <Summary>
    /// Same as PlayMusicString() except that this method accepts Callbacks.
    /// The Trace and Error callbacks will be used during the Parse of the Music Notes.
    /// @param szMusicNotes the Music string to be played on the MIDI output device
    /// @param traceCallbackProc the Callback to used to report Trace messages
    /// @param errorCallbackProc the Callback to used to report Error messages
    /// @param pUserData any user supplied data that should be sent to the Callback
    /// @return True if the notes were played successfully, False otherwise
    /// </Summary>
    MUSICNOTELIB_API bool PlayMusicStringCB(const TCHAR* szMusicNotes,
                                            LPFNTRACEPROC traceCallbackProc, 
                                            LPFNERRORPROC errorCallbackProc, 
                                            void* pUserData);

    /// <Summary>
    /// Plays Music string notes on the given MIDI Output device using the given Timer Resolution.
    /// Use PlayMusicString() to use default values.
    /// @param szMusicNotes the Music notes to be played
    /// @param nMidiOutPortID the device ID of the MIDI output port to be used for the play
    /// @param nTimerResMS preferred MIDI timer resolution, in MilliSeconds
    /// @return True if Play was successful, False otherwise
    /// </Summary>
    MUSICNOTELIB_API bool PlayMusicStringWithOpts(const TCHAR* szMusicNotes, int nMidiOutPortID, unsigned int nTimerResMS);

    /// <Summary>
    /// Same as PlayMusicStringWithOpts() except that this method accepts Callbacks.
    /// The Trace and Error callbacks will be used during the Parse of the Music Notes.
    /// @param szMusicNotes the Music notes to be played
    /// @param nMidiOutPortID the device ID of the MIDI output port to be used for the play
    /// @param nTimerResMS preferred MIDI timer resolution, in MilliSeconds
    /// @param traceCallbackProc the Callback to used to report Trace messages
    /// @param errorCallbackProc the Callback to used to report Error messages
    /// @param pUserData any user supplied data that should be sent to the Callback
    /// @return True if Play was successful, False otherwise
    /// </Summary>
    MUSICNOTELIB_API bool PlayMusicStringWithOptsCB(const TCHAR* szMusicNotes, 
                                                    int nMidiOutPortID, 
                                                    unsigned int nTimerResMS,
                                                    LPFNTRACEPROC traceCallbackProc, 
                                                    LPFNERRORPROC errorCallbackProc, 
                                                    void* pUserData);
    /// <Summary>
    /// Save the given MusicString content into a MIDI output file
    /// @param szMusicNotes Music Notes to be converted to MIDI output
    /// @param szOutputFilePath path of the MIDI output file
    /// @return True if the the content was saved successfully, False otherwise
    /// </Summary>
    MUSICNOTELIB_API bool SaveAsMidiFile(const TCHAR* szMusicNotes, const char* szOutputFilePath);

    //MUSICNOTELIB_API typedef void (*ParseErrorProc)(const MusicNoteLib::CParser*, MusicNoteLib::CParser::ErrorEventHandlerArgs* pEvArgs);
    //MUSICNOTELIB_API typedef void (*ParseTraceProc)(const MusicNoteLib::CParser*, MusicNoteLib::CParser::TraceEventHandlerArgs* pEvArgs);

    MUSICNOTELIB_API void Parse(const TCHAR* szNotes, LPFNTRACEPROC traceCallbackProc, void* pUserData);

} // extern "C"



} // namespace MusicNoteLib

#endif // __MUSICNOTE_LIB_H__EBEE094C_FF6E_43a1_A6CE_D619564F9C6A__

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

书信已泛黄 2024-09-13 00:33:56

错误就在这一行:

typedef  void (__stdcall *LPFNTRACEPROC)(void* pUserData, const TCHAR* szTraceMsg);

自从我“愤怒地”做C/C++以来已经有一段时间了,所以我在这里有点生疏了。某处存在类型不匹配 - 事实上,正如您通过将字符串包装在 _T 宏中所发现的那样。

The error is on this line:

typedef  void (__stdcall *LPFNTRACEPROC)(void* pUserData, const TCHAR* szTraceMsg);

It's been a while since I did C/C++ "in anger" so I'm a bit rusty here. There's a type mismatch somewhere - in fact as you spotted by wrapping the string in the _T macro.

无人问我粥可暖 2024-09-13 00:33:56

在 CPP 文件中包含 MusicNoteLib.h 之前,您需要包含声明 LPFNTRACEPROC 和 TCHAR 的标头。它可能是 Player.h,也许不应该像 ChrisF 建议的那样被注释掉,它也可能是 Windows 标头。

基本思想是,您需要查看编译器抱怨的行,找出这些行上的符号的声明位置,并包含具有这些声明的相应头文件。

You need to include the header(s) that declare LPFNTRACEPROC and TCHAR before you include MusicNoteLib.h in your CPP file. It could be Player.h which maybe shouldn't be commented out like ChrisF suggested, it could also be the Windows headers.

The basic idea is that you need to look at the lines the compiler is complaining about, figure out where the symbols on those lines are declared and include the appropriate header files that have those declarations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文