关于 “access violation at address××wtite of address××"的有关问题

求救关于 “access violation at address××:wtite of address××"的问题
这是我编写的一段用来采集设备读取的数据的程序,在Timer1Timer里测试读数据的情况。单步时候可以正常执行几遍,然后跳出这个错误,出现CPU的画面,不知道是什么原因。这个问题都折腾了好几天了,求高手帮忙。
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "Unit2.h"
#include "stdlib.h"
//---------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
HANDLE gm_hDevice;
int h,w;
int CurNum=0;
int gm_nPlus=16;
unsigned long gm_nCounts;
short gm_pBuffer[16*10];
short gm_pBufferTemp[16];
float gm_Temp1;
float gm_Temp2;
int gm_nRangeY;
int gm_nrTimes=0; //Y方向每导间隔
int ReadDataFalse=0;
//int gm_nStartPointy=0; //Y方向绘制开始点;
int ReadDataTrue=0;

HINSTANCE gm_Handle;
FARPROC gm_OpenDevice = NULL,
  gm_ReadData =NULL,
  gm_CloseDevice = NULL;
bool ReadDataResult =false;
bool CloseResult = false;
HANDLE (*lpOpenDevice)()= NULL;
bool (*lpReadData)(HANDLE ,short* ,ULONG *);
bool (*lpCloseDevice)(HANDLE);
//---------------------------------------
//---------------------------------------
typedef struct _PARAM
{
unsigned short nSenseDegree;
unsigned short nHightFre;
unsigned short nTimeConstant;
unsigned short nWorkFre;
unsigned short nModeOfSign;
unsigned short nGateOfJam;
unsigned short nHold1;
unsigned short nHold2;
}STRU_PARAM,*P_STRU_PARAM;
//---------------------------------------------------------------------

extern "C" _declspec(dllexport) HANDLE __stdcall OpenDevice();
extern "C" _declspec(dllexport) bool __stdcall CloseDevice(HANDLE hDevice);
extern "C" _declspec(dllexport) bool __stdcall ReadData(HANDLE hDevice,short* pBuffer,ULONG *nCounts);
extern "C" _declspec(dllexport) STRU_PARAM __stdcall ReadParam(HANDLE hDevice);

//-----------------------------------------------------------------------

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  Button3->Enabled=false;
  Button4->Enabled=false;
  Button5->Enabled=false;


}
//------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{

  Button1->Enabled = false;
  Button3->Enabled = false ;
  Button4->Enabled = true;
  Button5->Enabled = true;
  Button7->Enabled = false;
  Timer1->Enabled = true;

  //静态调用EEGAMP.dll中的OpenDevice函数
  gm_Handle = LoadLibrary("EEGAMP.dll");
  gm_OpenDevice = GetProcAddress(gm_Handle,"OpenDevice");
  gm_ReadData = GetProcAddress(gm_Handle,"ReadData");
  gm_CloseDevice = GetProcAddress(gm_Handle,"CloseDevice");
  lpOpenDevice = (HANDLE(__cdecl *)())gm_OpenDevice;
  lpReadData = (bool(__cdecl *)(HANDLE,short* ,ULONG *))gm_ReadData;
  lpCloseDevice = (bool(__cdecl *)(HANDLE))gm_CloseDevice;

  gm_hDevice = lpOpenDevice();

  if(gm_hDevice == INVALID_HANDLE_VALUE) Label1->Caption = "打开失败!";

}

//------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
do
  {
  ReadDataResult = lpReadData(gm_hDevice,&gm_pBuffer[0],&gm_nCounts);  
  ReadDataFalse++;
  if(ReadDataFalse == 10) //连续10次未读到数据就关闭设备,重新打开