By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,312 Members | 1,288 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,312 IT Pros & Developers. It's quick & easy.

How can I use PlaySound or play a .WAV file in a Visual C++ Windows Forms Application (.NET) Project?

P: n/a
I'm using Visual Studio .NET 2003.

I get a "Form1.h(242): error C2065: 'PlaySound' : undeclared identifier"
error all the time, I've been looking in MSDN for a couple of hours with no
luck, no idea, it's my first program, if you are so kind and could explain
me in detail.

Sorry for my english.

Regards.
Nov 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Can you post the code?
"Ángel Cabrera" <angel.cabrera.batista.847671@bit_.com> wrote in message
news:u8**************@TK2MSFTNGP12.phx.gbl...
I'm using Visual Studio .NET 2003.

I get a "Form1.h(242): error C2065: 'PlaySound' : undeclared identifier"
error all the time, I've been looking in MSDN for a couple of hours with no luck, no idea, it's my first program, if you are so kind and could explain
me in detail.

Sorry for my english.

Regards.

Nov 22 '05 #2

P: n/a
Sure.

Form1.h:

-----

#pragma once
namespace sound
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to
change the
/// 'Resource File Name' property for the managed resource
compiler tool
/// associated with all .resx files this class depends on.
Otherwise,
/// the designers will not be able to interact properly
with localized
/// resources associated with this form.
/// </summary>
public __gc class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}

protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::Button * button1;

private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container * components;

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->button1 = new System::Windows::Forms::Button();
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(8, 8);
this->button1->Name = S"button1";
this->button1->TabIndex = 0;
this->button1->Text = S"button1";
this->button1->Click += new System::EventHandler(this,
button1_Click);
//
// Form1
//
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->ClientSize = System::Drawing::Size(292, 273);
this->Controls->Add(this->button1);
this->Name = S"Form1";
this->Text = S"Form1";
this->ResumeLayout(false);

}

private: System::Void button1_Click(System::Object * sender,
System::EventArgs * e)
{
PlaySound("SOUND.WAV", NULL, SND_SYNC);
}

};
}

-----

Form1.cpp:

-----

#include "stdafx.h"
#include "Form1.h"
#include <windows.h>
#include <mmsystem.h>

using namespace sound;

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
Application::Run(new Form1());
return 0;
}

-----

"W.G. Ryan [eMVP]" <WilliamRyanATGmailDotcom> wrote in
news:ub**************@TK2MSFTNGP14.phx.gbl:
Can you post the code?
"Ángel Cabrera" <angel.cabrera.batista.847671@bit_.com> wrote in
message news:u8**************@TK2MSFTNGP12.phx.gbl...
I'm using Visual Studio .NET 2003.

I get a "Form1.h(242): error C2065: 'PlaySound' : undeclared
identifier" error all the time, I've been looking in MSDN for a
couple of hours with

no
luck, no idea, it's my first program, if you are so kind and could
explain me in detail.

Sorry for my english.

Regards.



Nov 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.