Rockwell Automation Publication 1789-UM002K-EN-P - January 2015
131
Develop External Routines
Chapter 7
Sounds.cpp
// Sounds.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include "RA_ExternalRoutines.h"
#include <Mmsystem.h>
#include <process.h>
HANDLE
hTerminate = NULL;
// DllMain needs to create a global event which all threads need to check for.
// This event will be used to tell the threads that the DLL is being unloaded
// and that it is time to terminate.
//
// Not creating and using this event can lead to access violations in the threads which
// will cause the SoftLogix controller to terminate and display a red X across the module.
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
hTerminate = CreateEvent (NULL, TRUE, FALSE, NULL);
return (TRUE);
case DLL_PROCESS_DETACH:
SetEvent (hTerminate);
Sleep (50); // give threads the chance to act on termination notice.
return (TRUE);
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
return (TRUE);
}
return (FALSE);
}
typedef enum rungStates {
FIRST_SCAN,
RUNG_TRUE,
RUNG_FALSE,
INVALID_STATE
} RUNGSTATES;
RUNGSTATES rungState = INVALID_STATE;
HANDLE hControllerState;
void PlaySound(char * Snd)
{
HGLOBAL hResLoad;
// handle to loaded resource
HRSRC hRes;
// handle/ptr. to res. info. in hDLL
LPTSTR lpResLock;
// pointer to resource data
BOOL bRes = TRUE;