void CTesterDlg::OnBeep()

{

            // TODO: Add your control notification handler code here

            bool bSuccess;

           

            HRESULT hr =  ::CoInitializeEx(

                                                NULL,                                                     // void * pvReserved,  Reserved

                                                COINIT_APARTMENTTHREADED            // DWORD dwCoInit     COINIT value

                                                ) ;

            switch(hr)

            {

            case S_OK:

                        bSuccess = true;

                        break;

            case S_FALSE:

                        bSuccess = true;                      // it has already been initialized

                        break;

            case RPC_E_CHANGED_MODE :

                        bSuccess = false;

                        ::AfxMessageBox("A previous call to CoInitializeEx specified a different concurrency model for the calling thread");

                        break;

            default:

                        ::AfxMessageBox("Unrecognized return from Error CoInitializeEx()");

            }

 

            if(bSuccess)

            {

 

                        IBeeper           *pBeeper = NULL;

                        HRESULT stdReturn = ::CoCreateInstance(

                                                               CLSID_Beeper,         //REFCLSID rclsid,     Class identifier (CLSID) of the object

                                                                NULL,                     // LPUNKNOWN pUnkOuter, Pointer to controlling IUnknown, NULL = the
                                                                                              // object is not being created as part of an aggregate

                                                               CLSCTX_ALL,          // DWORD dwClsContext,  Context for running executable code

                                                               IID_IBeeper,            // REFIID riid,        Reference to the identifier of the interface

                                                               (LPVOID *)&pBeeper            // LPVOID * ppv         Address of output variable that receives

                                                                                                         // the interface pointer requested in riid

                                                                );

                        if(stdReturn == S_OK)

                        {

                                    pBeeper->Beep(100);

                                    pBeeper->Release();

                        }

                        else

                        {

                                    ::AfxMessageBox("CoCreateInstance() error");

                        }

            }

            else

            {

                        ::AfxMessageBox("CoInitializeEx() error");

            }

 

            ::CoUninitialize( );

}

 

 

 

 

 

 

Home ] Up ]

e-mail the author

Last updated on Sunday, May 19, 2002 06:53:57 -0400

Copy Right of Biyee 1996 - 2002