Rev 197 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#include <windows.h>
#include <drsread.h>
/* The two macros below are used as error return codes */
/* in case the DLL does not load, or is missing one or */
/* more functions, respectively. You must define them */
/* to whatever values are meaningful for your DLL. */
#define kFailedToLoadDLLError ???
#define kCouldNotFindFunction ???
static HINSTANCE DLLHandle;
/* Declare the variables that hold the addresses of the function */
/* pointers. */
static void (__cdecl *DRSSetMask_Ptr)(int mask);
static void (__cdecl *DRSSetTriggerType_Ptr)(int type);
static void (__cdecl *DRSSetFrequency_Ptr)(int freq);
static void (__cdecl *DRSSetRange_Ptr)(double range);
static void (__cdecl *DRSSetTriggerChannel_Ptr)(int channel);
static void (__cdecl *DRSSetTriggerDelay_Ptr)(double delay);
static void (__cdecl *DRSSetTriggerLevel_Ptr)(double level);
static void (__cdecl *DRSSetTriggerPolarity_Ptr)(int polarity);
static float *(__cdecl *DRSGetTime_Ptr)(int ch);
static float *(__cdecl *DRSGetWave_Ptr)(int ch);
static int (__cdecl *DRSInit_Ptr)();
static int (__cdecl *DRSRead_Ptr)(int drstimer);
static int (__cdecl *DRSEnd_Ptr)();
static int (__cdecl *DRSToBuffer_Ptr)(unsigned char *p, int m_evSerial);
static int (__cdecl *DRSIsTimeout_Ptr)();
static void (__cdecl *DRSSetTimeout_Ptr)();
static void (__cdecl *DRSSigInt_Ptr)(int k);
/* Load the DLL and get the addresses of the functions */
static int LoadDLLIfNeeded(void)
{
if (DLLHandle)
return 0;
DLLHandle = LoadLibrary("drsread.dll");
if (DLLHandle == NULL) {
return kFailedToLoadDLLError;
}
if (!(DRSSetMask_Ptr = (void*) GetProcAddress(DLLHandle, "DRSSetMask")))
goto FunctionNotFoundError;
if (!(DRSSetTriggerType_Ptr = (void*) GetProcAddress(DLLHandle,
"DRSSetTriggerType")))
goto FunctionNotFoundError;
if (!(DRSSetFrequency_Ptr = (void*) GetProcAddress(DLLHandle,
"DRSSetFrequency")))
goto FunctionNotFoundError;
if (!(DRSSetRange_Ptr = (void*) GetProcAddress(DLLHandle, "DRSSetRange")))
goto FunctionNotFoundError;
if (!(DRSSetTriggerChannel_Ptr = (void*) GetProcAddress(DLLHandle,
"DRSSetTriggerChannel")))
goto FunctionNotFoundError;
if (!(DRSSetTriggerDelay_Ptr = (void*) GetProcAddress(DLLHandle,
"DRSSetTriggerDelay")))
goto FunctionNotFoundError;
if (!(DRSSetTriggerLevel_Ptr = (void*) GetProcAddress(DLLHandle,
"DRSSetTriggerLevel")))
goto FunctionNotFoundError;
if (!(DRSSetTriggerPolarity_Ptr = (void*) GetProcAddress(DLLHandle,
"DRSSetTriggerPolarity")))
goto FunctionNotFoundError;
if (!(DRSGetTime_Ptr = (void*) GetProcAddress(DLLHandle, "DRSGetTime")))
goto FunctionNotFoundError;
if (!(DRSGetWave_Ptr = (void*) GetProcAddress(DLLHandle, "DRSGetWave")))
goto FunctionNotFoundError;
if (!(DRSInit_Ptr = (void*) GetProcAddress(DLLHandle, "DRSInit")))
goto FunctionNotFoundError;
if (!(DRSRead_Ptr = (void*) GetProcAddress(DLLHandle, "DRSRead")))
goto FunctionNotFoundError;
if (!(DRSEnd_Ptr = (void*) GetProcAddress(DLLHandle, "DRSEnd")))
goto FunctionNotFoundError;
if (!(DRSToBuffer_Ptr = (void*) GetProcAddress(DLLHandle, "DRSToBuffer")))
goto FunctionNotFoundError;
if (!(DRSIsTimeout_Ptr = (void*) GetProcAddress(DLLHandle, "DRSIsTimeout")))
goto FunctionNotFoundError;
if (!(DRSSetTimeout_Ptr = (void*) GetProcAddress(DLLHandle, "DRSSetTimeout")))
goto FunctionNotFoundError;
if (!(DRSSigInt_Ptr = (void*) GetProcAddress(DLLHandle, "DRSSigInt")))
goto FunctionNotFoundError;
return 0;
FunctionNotFoundError:
FreeLibrary(DLLHandle);
DLLHandle = 0;
return kCouldNotFindFunction;
}
/* Glue Code for each of the DLL functions */
void DRSSetMask(int mask)
{
int dllLoadError;
if (dllLoadError = LoadDLLIfNeeded())
return;
(*DRSSetMask_Ptr)(mask);
}
void DRSSetTriggerType(int type)
{
int dllLoadError;
if (dllLoadError = LoadDLLIfNeeded())
return;
(*DRSSetTriggerType_Ptr)(type);
}
void DRSSetFrequency(int freq)
{
int dllLoadError;
if (dllLoadError = LoadDLLIfNeeded())
return;
(*DRSSetFrequency_Ptr)(freq);
}
void DRSSetRange(double range)
{
int dllLoadError;
if (dllLoadError = LoadDLLIfNeeded())
return;
(*DRSSetRange_Ptr)(range);
}
void DRSSetTriggerChannel(int channel)
{
int dllLoadError;
if (dllLoadError = LoadDLLIfNeeded())
return;
(*DRSSetTriggerChannel_Ptr)(channel);
}
void DRSSetTriggerDelay(double delay)
{
int dllLoadError;
if (dllLoadError = LoadDLLIfNeeded())
return;
(*DRSSetTriggerDelay_Ptr)(delay);
}
void DRSSetTriggerLevel(double level)
{
int dllLoadError;
if (dllLoadError = LoadDLLIfNeeded())
return;
(*DRSSetTriggerLevel_Ptr)(level);
}
void DRSSetTriggerPolarity(int polarity)
{
int dllLoadError;
if (dllLoadError = LoadDLLIfNeeded())
return;
(*DRSSetTriggerPolarity_Ptr)(polarity);
}
float *DRSGetTime(int ch)
{
int dllLoadError;
if (dllLoadError = LoadDLLIfNeeded())
return ???;
return (*DRSGetTime_Ptr)(ch);
}
float *DRSGetWave(int ch)
{
int dllLoadError;
if (dllLoadError = LoadDLLIfNeeded())
return ???;
return (*DRSGetWave_Ptr)(ch);
}
int DRSInit()
{
int dllLoadError;
if (dllLoadError = LoadDLLIfNeeded())
return dllLoadError;
return (*DRSInit_Ptr)();
}
int DRSRead(int drstimer)
{
int dllLoadError;
if (dllLoadError = LoadDLLIfNeeded())
return dllLoadError;
return (*DRSRead_Ptr)(drstimer);
}
int DRSEnd()
{
int dllLoadError;
if (dllLoadError = LoadDLLIfNeeded())
return dllLoadError;
return (*DRSEnd_Ptr)();
}
int DRSToBuffer(unsigned char *p, int m_evSerial)
{
int dllLoadError;
if (dllLoadError = LoadDLLIfNeeded())
return dllLoadError;
return (*DRSToBuffer_Ptr)(p, m_evSerial);
}
int DRSIsTimeout()
{
int dllLoadError;
if (dllLoadError = LoadDLLIfNeeded())
return dllLoadError;
return (*DRSIsTimeout_Ptr)();
}
void DRSSetTimeout()
{
int dllLoadError;
if (dllLoadError = LoadDLLIfNeeded())
return;
(*DRSSetTimeout_Ptr)();
}
void DRSSigInt(int k)
{
int dllLoadError;
if (dllLoadError = LoadDLLIfNeeded())
return;
(*DRSSigInt_Ptr)(k);
}