unit1.cpp
extern "C" __declspec(dllexport) __stdcall void PcEcr(void); //数据通讯
extern "C" __declspec(dllexport) __stdcall void Modem(void); //拨号
bool lCom = false; //这里是全局变量
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
//---------------------------------------------------------------------------
//数据通讯
void __stdcall PcEcr(void)
{
dlg_Comm = new Tdlg_Comm(NULL); //显示通讯界面
dlg_Comm->ShowModal();
delete dlg_Comm;
}
//----------------------------------------------------------------------------
//数据通讯
void __stdcall Modem(void)
{
dlg_Modem = new Tdlg_Modem(NULL); //显示通讯界面
dlg_Modem->ShowModal();
delete dlg_Modem;
}
unit2.cpp
Tdlg_Comm *dlg_Comm;
extern bool lCom;
//---------------------------------------------------------------------------
__fastcall Tdlg_Comm::Tdlg_Comm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
DWORD CALLBACK ModemThread(LPVOID)
{
return 1;
}
void __fastcall Tdlg_Comm::FormActivate(TObject *Sender)
{
DWORD CommID;
HANDLE CommHandle;
lCom = true; //让lCom = true
CommHandle = CreateThread(NULL,NULL,ModemThread,NULL,NULL,&CommID);
if (CommHandle == NULL)
{
Application->MessageBoxA("创建通讯线程失败","信息提示",MB_OK);
return;
}
}
unit3.cpp
Tdlg_Modem *dlg_Modem;
extern bool lCom;
//---------------------------------------------------------------------------
__fastcall Tdlg_Modem::Tdlg_Modem(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
DWORD CALLBACK CommThread(LPVOID)
{
if (!lCom)
{
Application->MessageBoxA("创建通讯线程失败","信息提示",MB_OK);
}
return 1;
}
void __fastcall Tdlg_Modem::FormActivate(TObject *Sender)
{
DWORD CommID;
HANDLE CommHandle;
CommHandle = CreateThread(NULL,NULL,CommThread,NULL,NULL,&CommID);
if (CommHandle == NULL)
{
Application->MessageBoxA("创建通讯线程失败","信息提示",MB_OK);
return;
}
}
按道理,我在unit2中已经让 lCom = true
但为什么在 unit3中lCom = false;
好象没有改变啊
--------------------next---------------------
阅读(1167) | 评论(0) | 转发(0) |