Actual C++ Code

 

People sometimes ask just exactly what it is I do as a programmer.  It's hard to explain without lots of boring background information about processors, operating systems, compilers, binary numbering systems, and so on which no one ever wants to hear.  But it's easy enough to show you an example.  Here's some actual C++ code from an application I wrote recently. 

So what I do is sit at my computer, think for a bit, and then type a bit, and repeat, for hours on end. Sometimes I do web searches over and over and over, looking for sample code and other assistance.  Almost makes accounting sound interesting, doesn't it?  Actually, writing software is fun—It's like building cool new machines without ever getting your hands dirty.

#include "stdafx.h"

#include "MyObject.h"
#include "MainDlg.h"
#include "WaveInfoDlg.h"
#include "Connection.h"
#include "Options.h"

void MyAdvise( int msg, LPARAM lparam )
{
    PostMessage( GETMAINDLGPTR->m_hWnd, WM_MYADVISE, (WPARAM) msg, lparam );
}

void PostMsg( const char * pszMsg )
{
    MyAdvise( ADVISE_SCROLLINGMSG, (LPARAM) pszMsg );
}

UINT CMyObject::StartFunction( LPVOID pParam )
{
    CMyObject * pObj = (CMyObject*) pParam;
    BOOL bInitRes = pObj->Init( );
    if ( bInitRes )
        pObj->Run( );
    int cleanupRes = pObj->Cleanup( );
    return bInitRes ? cleanupRes : INITFAILED;
}

IMPLEMENT_DYNAMIC( CMyObject, CObject );

CMyObject::CMyObject( )
{
    m_pWID = NULL;
    m_pThread = NULL;
    m_cbBitstream = 0;
    memset( &m_waveFormat, 0, sizeof( m_waveFormat ) );
    m_waveFormat.wFormatTag = WAVE_FORMAT_PCM;         // i.e., uncompressed
    m_waveFormat.nChannels = 1;                        // mono
    m_waveFormat.nSamplesPerSec = 8000;
    m_waveFormat.nAvgBytesPerSec = 16000;
    m_waveFormat.nBlockAlign = 2;
    m_waveFormat.wBitsPerSample = 16;

    for ( int i = TERMINATE_EVENT; i <= COMM_EVENT; i++ )
    {
        BOOL bManualReset = ( i == COMM_EVENT );
        m_aEventHandles[ i ] = ::CreateEvent( NULL, bManualReset, FALSE, NULL );
        ASSERT( m_aEventHandles[ i ] );		// ca ntr: assume this can't fail
    }
    memset( m_pLastPlottedPixels, 192, sizeof( m_pLastPlottedPixels ) );
    m_cbWaveDataPlayedOrRecorded = 0;
    m_nDrawWaveBytesCounter = 0;
};

CMyObject::~CMyObject( )
{
    ASSERT( ! m_pThread );
    for ( int i = TERMINATE_EVENT; i <= COMM_EVENT; i++ )
    {
        CloseHandle( m_aEventHandles[ i ] );
    }
}

DWORD CMyObject::GetExitCode( )
{
    if ( ! m_pThread )
        return NEVERCREATED;
    DWORD exitCode; VERIFY( ::GetExitCodeThread( m_pThread->m_hThread, & exitCode ) );
    return exitCode;
}
     
     

Home Up Next

www.CharlieAnderson.com  •  Since 1998, Your Home for Charlie Anderson Information  •  Send me email: info@charlieanderson.com 


All Content © 1998-2002 Charles R. Anderson  •  This page was last modified on 11/13/2003