Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2341658
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:05:47

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) |
给主人留下些什么吧!~~