   Errors
  Hi,I have got these errors on my DirectX 9 program. Please could someone help fix them. I want my program is initialize DirectSound so my game can play audio files and music.error LNK2001: unresolved external symbol "struct HWND__ * hWnd" (?hWnd@@3PAUHWND__@@A)error LNK2019: unresolved external symbol _DirectSoundCreate@12 referenced in function "bool __cdecl Sound_Init(void)" (?Sound_Init@@YA_NXZ)fatal error LNK1120: 2 unresolved externals--Snippet for DirectSound--#include <dsound.h>extern HWND hWnd;static LPDIRECTSOUND lpDS;bool Sound_Init(void){if (DS_OK==DirectSoundCreate(NULL,&lpDS,NULL)) //create direct sound object    {   //ok, DirectSound Object created, let's take control now...   if (DS_OK==IDirectSound_SetCooperativeLevel(lpDS, hWnd, DSSCL_EXCLUSIVE))   {  //MessageBox(hMainWnd,"Cooperative Level Succefully Set!","Good!!",MB_OK);  return TRUE;   }   else //SetCoop was unsuccessful, let's give up control   {  IDirectSound_Release(lpDS);  MessageBox(hWnd,L"Set Cooperative Level didn't Work!",L"BAD!!",MB_OK);  return FALSE;   }    }    else  //DSObj creation was unsuccessful    {   MessageBox(hWnd,L"Could Not Create Direct Sound Object",L"Error!",MB_OK);   return (FALSE);    }}/*here's a simple function to shut down direct sound when you're done with it */void Sound_Exit(void){    if (lpDS)    {   IDirectSound_Release(lpDS);    }    else    {   MessageBox(hWnd,L"Sound was not initialized and cannot Exit!", L"Error!",MB_OK);    }}   
  Looks like you forgot to link the DirectSound libraries, (that's what those .lib files are) though the specifics of how to do so are compiler-dependent. Seeing as your error messages appear to come from MSVC, I'll try and cover how to do it in there.First off, open your project up and then open the 'Tools' menu at the top of your screen, and then select the 'Options' item. You should now be looking at a window with a tree list on the left and a bunch of listboxes/text fields on the right. In the tree list, look for the 'Projects and Solutions' node (third major one from the top, at least in MSVC2008) and finally click on the 'VC++ Directories' subnode. The right side of the window should now change, having two dropdown listboxes and a bunch of directory names. In the 'Show Directories For' listbox, (top right) select 'Library files.' Now click the 'new line' button and direct it to the 'Lib\x86' subdirectory of wherever you installed the DirectX SDK. If you plan on making 64-bit apps, also repeat the process after changing the 'Platform' listbox to 'x64,' though you want to instead use the 'Lib\x64' subdirectory now. Once you're all set, close that window and add the line#pragma comment(lib, "dsound.lib") after the #include <dsound.h> in the file you posted. If you did this correctly, you should no longer receive the second error.On the other hand, your first error should be considerably easier to fix-- basically, when you entered the line extern HWND hWnd, you told the compiler that you would make a global HWND variable named hWnd in another source file/translation unit, and you want to use that same variable in this file/translation unit. That error message is the compiler telling you that it couldn't find said variable. From the looks of things, it appears that you would actually be able to use hMainWnd instead. Thus, delete the error-producing external variable declaration and replace all uses of hWnd with hMainWnd-- MSVC's find/replace (ctrl+h IIRC) would probably be good for this.And on an unrelated note, I would suggest ditching the tutorial you're using, (assuming you are indeed following one) as it appears they employ rather poor C++ style conventions by using externs/global variables. It's optional, and unfortunately I don't know of any really good ones off the top of my head, but it might be worth looking into.   ;  Hi,I still got 2 error remaining. I added the library to the code.error LNK2001: unresolved external symbol "struct HWND__ * hWnd" (?hWnd@@3PAUHWND__@@A)fatal error LNK1120: 1 unresolved externalsThank you   ;  You've declared HWND hWnd as extern somewhere, but never instantiated it.I'd highly recommend stopping with DirectX until you're comfortable with C++ - blindly copying source code and then getting stuck every time you get an error will just cause things to take 10 times as long as they should.[Edited by - Evil Steve on April 20, 2010 3:40:10 AM]