我正在制作一个 C++ 程序来播放一些 mp3 文件并且遇到了麻烦。我收到未找到标识符的错误。除了包括标题之外,任何人都可以给我一些建议吗?
这是我的代码:
#include "fmod.h"
#include "windows.h"
#include <string>
#include <iostream>
#include <msclr\marshal_cppstd.h>
#include <conio.h>
#pragma comment (lib, "fmodex64_vc.lib")
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace std;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
FSOUND_SAMPLE* handle;
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TextBox^ textBox1;
protected:
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::ListBox^ list;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->list = (gcnew System::Windows::Forms::ListBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(97, 23);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(518, 20);
this->textBox1->TabIndex = 0;
this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged);
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(12, 26);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(79, 13);
this->label1->TabIndex = 1;
this->label1->Text = L"Libray Location";
//
// list
//
this->list->FormattingEnabled = true;
this->list->Location = System::Drawing::Point(15, 80);
this->list->Name = L"list";
this->list->Size = System::Drawing::Size(757, 472);
this->list->TabIndex = 2;
//
// button1
//
this->button1->Location = System::Drawing::Point(697, 571);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 3;
this->button1->Text = L"Play";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(616, 571);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(75, 23);
this->button2->TabIndex = 4;
this->button2->Text = L"Refresh";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(784, 606);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->list);
this->Controls->Add(this->label1);
this->Controls->Add(this->textBox1);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
this->PerformLayout();
}
private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
msclr::interop::marshal_context context;
std::string standardString = context.marshal_as<std::string>(textBox1->Text);
GetAllFiles(standardString);
//list->Items->Add();
}
void GetAllFiles(string sPath){
WIN32_FIND_DATA FindFileData;
string sTmpPath = sPath;
sTmpPath += "\\*.*";
HANDLE hFind = FindFirstFile( sTmpPath.c_str(), &FindFileData );
if ( hFind == INVALID_HANDLE_VALUE )
return;
else {
do {
if ( ( FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) ) {
// if directory:
if ( strcmp(".", FindFileData.cFileName ) && strcmp("..", FindFileData.cFileName) ) {
sTmpPath = sPath;
sTmpPath += "\\";
sTmpPath += FindFileData.cFileName;
GetAllFiles( sTmpPath.c_str() );
}
}
else // if file:
{
sTmpPath = sPath;
sTmpPath += "\\";
sTmpPath += FindFileData.cFileName;
string fileType = sTmpPath.substr(sTmpPath.length()-3, sTmpPath.length());
if(fileType == "mp3"){
String^ myTempPath = gcnew String(sTmpPath.c_str());
list->Items->Add(myTempPath);//cout << sTmpPath << endl;
}
}
} while ( FindNextFile( hFind, &FindFileData) != 0 );
FindClose( hFind );
}
return;
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
// init FMOD sound system
FSOUND_Init (44100, 32, 0);
// load and play mp3
handle=FSOUND_Sample_Load (0,"E:\\Steve\\Music\\2 Pac\\Unknown Album\\Temptations.mp3",0, 0, 0);
FSOUND_PlaySound (0,handle);
FSOUND_Sample_Free (handle);
FSOUND_Close();
}
};
这是我的错误:
1>c:\users\steve\documents\visual studio 2010\projects\testforms\testforms\Form1.h(26): error C2143: syntax error : missing ';' before '*'
1>c:\users\steve\documents\visual studio 2010\projects\testforms\testforms\Form1.h(26): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\steve\documents\visual studio 2010\projects\testforms\testforms\Form1.h(26): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\steve\documents\visual studio 2010\projects\testforms\testforms\Form1.h(187): error C3861: 'FSOUND_Init': identifier not found
1>c:\users\steve\documents\visual studio 2010\projects\testforms\testforms\Form1.h (190): error C2065: 'handle' : undeclared identifier
1>c:\users\steve\documents\visual studio 2010\projects\testforms\testforms\Form1.h(190): error C3861: 'FSOUND_Sample_Load': identifier not found
1>c:\users\steve\documents\visual studio 2010\projects\testforms\testforms\Form1.h(191): error C2065: 'handle' : undeclared identifier
1>c:\users\steve\documents\visual studio 2010\projects\testforms\testforms\Form1.h (191): error C3861: 'FSOUND_PlaySound': identifier not found
1>c:\users\steve\documents\visual studio 2010\projects\testforms\testforms\Form1.h(192): error C2065: 'handle' : undeclared identifier
1>c:\users\steve\documents\visual studio 2010\projects\testforms\testforms\Form1.h(192): error C3861: 'FSOUND_Sample_Free': identifier not found
1>c:\users\steve\documents\visual studio 2010\projects\testforms\testforms\Form1.h(193): error C3861: 'FSOUND_Close': identifier not found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========