I wrote this two functions:
void Audio::openSoundDevice()
{
HWAVEOUT hWaveOut ;
WAVEFORMATEX wfx ;
MMRESULT result ;
LPSTR block ;
DWORD blockSize ;
wfx.nSamplesPerSec = 44100 ;
wfx.wBitsPerSample = 16 ;
wfx.nChannels = 2 ;
wfx.cbSize= 0 ;
wfx.wFormatTag = WAVE_FORMAT_PCM ;
wfx.nBlockAlign = (wfx.wBitsPerSample >> 3) * wfx.nChannels ;
wfx.nAvgBytesPerSec = wfx.nBlockAlign * wfx.nSamplesPerSec ;
if(waveOutOpen( &hWaveOut, WAVE_MAPPER, &wfx, 0, 0, CALLBACK_NULL ) !=MMSYSERR_NOERROR)
{
fprintf(stderr, "unable to open WAVE_MAPPER device\n") ;
ExitProcess(1) ;
}
printf("The Wave Mapper device was opened successfully!\n") ;
waveOutClose(hWaveOut) ;
//Below Line ruins Everything:(
if((block = loadAudioBlock("C:\\Windows\\Media\\ding.wav", &blockSize)) == NULL)
{
fprintf(stderr, "Unable to load file\n");
ExitProcess(1) ;
}
writeAudioBlock(hWaveOut, block, blockSize) ;
waveOutClose(hWaveOut) ;
}
and
LPSTR loadAudioBlock(const char* filename, DWORD* blockSize)
{
HANDLE hFile = INVALID_HANDLE_VALUE ;
DWORD size = 0 ;
DWORD readBytes = 0 ;
void* block = NULL ;
/* * open the file */
if((hFile = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL )) == INVALID_HANDLE_VALUE) { return NULL ; }
/* * get it's size, allocate memory and read the file * into memory. don't use this on large files! */
do {
if((size = GetFileSize(hFile, NULL)) == 0) { break ; }
if((block = HeapAlloc(GetProcessHeap(), 0, size)) == NULL) { break ; }
ReadFile(hFile, block, size, &readBytes, NULL) ;
}
while(0) ;
CloseHandle(hFile) ;
*blockSize = size ;
return (LPSTR)block ;
}
As you see "openSoundDevice" calls "loadAudioBlock" but when it is happening the "Error LNK2019:Unresolved Externals" Pops up.I changed Const char* to LPCWSTR,changing Unicode to multibyte and everything else but nothing happen.What is problem of this code?
Thanks