Click here to Skip to main content
15,914,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello...!
I want to write a C/C++ program to play audio file. I'm successful to write this code in visual studio but when i tried the code in turbo c then there are errors.

What I have tried:

#include "stdafx.h"
#include "strsafe.h"
#include "MMSystem.h"
#pragma comment(lib, "winmm.lib")

void main() {
     PlaySound(TEXT("File path.wav"), NULL, SND_FILENAME | SND_LOOP);
}


This is the code i tried in visual studio. Now to wanna to play audio in turbo. Please help me.
Thanks!
Posted
Updated 10-Jun-18 0:18am
Comments
[no name] 10-Jun-18 0:41am    
Usama Iftikhar Butt 10-Jun-18 1:42am    
Hi i am not logged in this web site and they not allow to see content without login.
Can you send me a screen shot of web.
Please
Usama Iftikhar Butt 10-Jun-18 5:11am    
Hellow
i try this method there are errors.
Mohibur Rashid 10-Jun-18 0:46am    
TurboC? TurboC do not have right library to handle. I don't think you can work with windows API with turboC.

macro TEXT is declared in windows.h header file and it belongs to visual studio. TEXT is there to handle UNICODE. TurboC cannot handle unicode.

Turbo C/C++ is an ancient compiler from the DOS and 16-bit Windows times (see Turbo C++ - Wikipedia[^]).

While it can be installed on recent Windows versions that does not mean that you can create executables running on recent Windows versions. It creates 16-bit executables which are not supported anymore since Windows 8 (you would need the Embarcadero BCC32C/BCC32X C++ compiler to create executables that can be run by recent Windows versions).

Your code for Visual Studio does not work with Turbo C++ because it contains two VS specific lines not supported by Turbo C:
  1. stdafx.h is a file used (and created) by VS to support pre compiled headers and include the required Windows header files
  2. #pragma comment(lib, ...) is as VS specific preprocessor directive to link with the specified library

To compile your code with any other C/C++ compiler, you would have to configure it to use the include and library file paths of the Windows SDK, remove the two lines mentioned above, probably add including Windows.h, and link with winmm.lib.

I strongly suggest to not use Turbo C/C++ anymore besides you want to write a DOS application. But those can't use Windows libraries.
 
Share this answer
 
From here:C++ How to play sound using Turbo C++[^]

C++
#include <mmsystem.h>

BOOL sndPlaySound(
  LPCSTR lpszSound,  
  UINT fuSound      
);


youll also have to link to winmm.lib which can be done by adding

C++
#pragma comment(lib,"winmm.lib")


to your source file
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900