1

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

Adam H. Peterson
  • 4,511
  • 20
  • 28
user2998131
  • 205
  • 1
  • 2
  • 6
  • 1
    Is `loadAudioBlock` maybe supposed to be member of `Audio`? –  Jan 28 '14 at 16:59
  • what is the exact error string? – odinthenerd Jan 28 '14 at 17:00
  • error LNK2019: unresolved external symbol "public: char * __thiscall Audio::loadAudioBlock(char const *,unsigned long *)" (?loadAudioBlock@Audio@@QAEPADPBDPAK@Z) referenced in function "public: void __thiscall Audio::openSoundDevice(void)" (?openSoundDevice@Audio@@QAEXXZ) – user2998131 Jan 28 '14 at 17:13
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – elixenide Jan 28 '14 at 17:14
  • it was not memeber of Audio.Thanks Nabla – user2998131 Jan 28 '14 at 17:15

0 Answers0