在DLL中包含了Form, 主程序使用多线程的模式动态加载DLL, 为了使DLL中的界面能排列整齐,在DLL中的Form_Create中动态改变Form的位置, 但是运行的时候却报错,请Victor指点.
动态库的入口函数: 其中iThreadSeq为全局变量
extern "C" bool __export Programming(char *sSourceFile,TStrings *lpList,int iSeq)
{
bResult = false;
iThreadSeq = iSeq;
sFileName = sSourceFile;
Form1 = new TForm1(NULL);
Form1->ShowModal();
delete Form1;
return bResult;
}
DLL所包含的Form1 的FormCreate
void __fastcall TForm1::FormCreate(TObject *Sender)
{
if(iThreadSeq == 1) //位
{
Form1->Top = 0;
Form1->Left = 0;
Form1->Width = 510;
Form1->Height = 360;
}
if(iThreadSeq == 2) //位
{
Form1->Top = 0;
Form1->Left = 511;
Form1->Width = 510;
Form1->Height = 360;
}
if(iThreadSeq == 3) //位
{
Form1->Top = 361;
Form1->Left = 0;
Form1->Width = 510;
Form1->Height = 360;
}
if(iThreadSeq == 4) //位
{
Form1->Top = 361;
Form1->Left = 511;
Form1->Width = 510;
Form1->Height = 360;
}
}
// 加载DLL主控程序的线程函数ProThread.CPP
__fastcall ProThread::ProThread(bool CreateSuspended,String sDllFile,String sSourceFile,int iSeq)
: TThread(CreateSuspended)
{
sLoadDllFile = sDllFile;
sProFile = sSourceFile;
iThreadNum = iSeq;
}
//---------------------------------------------------------------------------
void __fastcall ProThread::Execute()
{
//---- Place thread code here ----
HINSTANCE ins;
ins = LoadLibrary(sLoadDllFile.c_str());
if(ins == NULL) // Loading DLL file error
{
return;
}
//Loading DLL Function
FARPROC proc;
proc = GetProcAddress(ins,"_Programming");
if(proc == NULL)
{
FreeLibrary(ins);
return;
}
typedef bool(*FUNC)(char *,TStrings *,int);
FUNC aFunc = (FUNC)proc;
Application->ProcessMessages();
bool bResult;
bResult =false;
bResult = aFunc(sProFile.c_str() ,NULL,iThreadNum);
if(bResult == true)
ReturnValue = 1;
else
ReturnValue = 2;
}
ProThread.H
//---------------------------------------------------------------------------
#ifndef ProThreadH
#define ProThreadH
//---------------------------------------------------------------------------
#include
//---------------------------------------------------------------------------
class ProThread : public TThread
{
private:
String sLoadDllFile;
String sProFile;
int iThreadNum;
protected:
void __fastcall Execute();
public:
__fastcall ProThread(bool CreateSuspended, String sDllFile,String sSourceFile,int iSeq);
};
//---------------------------------------------------------------------------
#endif
--------------------next---------------------
阅读(1074) | 评论(0) | 转发(0) |