atl activex异步回调的产生的诡异有关问题,每调用一次函数,回调Js便多了一次。跪求大家给看看

atl activex异步回调的产生的诡异问题,每调用一次函数,回调Js便多了一次。跪求大家给看看。
使用ATL 开发了一个ActiveX,使用多线程异步的去调用事件,事件中回调js代码。

主要代码:
主要调用的代码和线程代码,
在线程中使用PostMessage发送自定义消息给控件,控件接受自定义消息然后Map到对应的函数上
PosAsync.cpp

unsigned __stdcall LogonMethod(LPVOID arg)
{
int rtn;
unsigned char RCode[1024];
unsigned char RInfo[1024];

memset(RCode,0,1024);
memset(RInfo,0,1024);

//char szBuff[64];
//sprintf(szBuff, "%d", _TranNo);
//MessageBoxA(NULL,szBuff,"交易号",MB_OK);

rtn = MisPosLogon(RCode,RInfo,_ComPort,_TranNo);
if (rtn == 0)
{
if (strcmp((char*)RCode,"00") == 0)
{
MessageBoxA(NULL,(LPCSTR)RInfo,"签到返回信息",MB_OK);
result = ::SysAllocString(L"0");
}
else
{
result = ::SysAllocString(L"-1");
}

}
else
{
result = ::SysAllocString(L"-2");
}

//char szBuff[64];
//sprintf(szBuff, "%p", _m);
//MessageBoxA(NULL, szBuff, "Title", MB_OK);

PostMessage(_m, WM_LOGONCOMPLETED, NULL, NULL);
_endthreadex(0);
return 0;
}

STDMETHODIMP CPosAsync::Logon(SHORT ComPort, SHORT TranNo)
{
_ComPort = ComPort;
_TranNo = TranNo;
_m = m_hWnd;
::PostMessage(_m, WM_LOGONCOMPLETED, NULL, NULL);
//_beginthreadex(NULL, NULL, LogonMethod, NULL, NULL, NULL);
return S_OK;
}





unsigned __stdcall SaleMethod(LPVOID arg)
{
int rtn;
unsigned char RCode[1024];
unsigned char RInfo[1024];

memset(RCode,0,1024);
memset(RInfo,0,1024);

USES_CONVERSION;
char *amt = OLE2A(_Amout);
::MessageBoxA(NULL, (LPCSTR)amt,"test",MB_OK);

rtn = MisPosSale(RCode,RInfo,(unsigned char*)amt,_ComPort,_TranNo);
if (rtn == 0)
{
if (strcmp((char*)RCode,"00") == 0)
{
::MessageBoxA(NULL,(LPCSTR)RInfo,"test",MB_OK);
result = _com_util::ConvertStringToBSTR((const char *)RInfo);

}
else
{
result = ::SysAllocString(L"-1");
}

}
else
{
result = ::SysAllocString(L"-2");
}

PostMessage(_m, WM_SALECOMPLETED, NULL, NULL);
_endthreadex(0);
return 0;
}

STDMETHODIMP CPosAsync::Sale(SHORT ComPort, short TranNo, BSTR Amout)
{
_ComPort = ComPort;