BCB5编写DLL、BCB5调用并写入
DLL:
1.cpp:
USEFORM("About2.cpp", Form2);
extern "C" __declspec(dllexport) __stdcall void About();
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* )
{
return 1;
}
void __stdcall About()
{
Form2 = new TForm2(NULL);
Form2->ShowModal();
delete Form2;
}
2.cpp:
TForm2 *Form2;
__fastcall TForm2::TForm2(TComponent* AOwner)
: TForm(AOwner)
{
}
void __stdcall About()
{
Form2 = new TForm2(NULL);
Form2->ShowModal();
delete Form2;
}
void __fastcall TForm2::BitBtn1Click(TObject *Sender)
{
Close();
}
调用:
void __fastcall TMainForm1::N5Click(TObject *Sender)
{
HINSTANCE hInst = LoadLibrary("About.dll");
if(hInst==NULL)
{
ShowMessage("Load dll error");
return;
}
if (hInst){
Beep();
(FARPROC)About=GetProcAddress(hInst,"About");
if(About==NULL)
{
FreeLibrary(hIst);
ShowMessage("Get function address error");
return;
}
LPTSTR a,b,c,d;
a="系统名称:";
b="版 本:" ;
c="版权:" ;
d="备注:";
About(a,b,c,d);
}
freeLibrary("About.dll");
}
请问:我在FORM2中设置Label1、2、3、4。想让Label1->Caption=a、Label2->Caption=b....Label4->Caption=d
DLL如何编写代码,弄了好几天也没成功。请各位高手帮忙了。
[解决办法]
extern "C" __declspec(dllexport) __stdcall void About(char *a,char*b,char*c,char*d);void __stdcall About(char *a,char*b,char*c,char*d){ Form2 = new TForm2(NULL); Form2->Label1->Caption=a;Form2->Label2->Caption=b;Form2->Label3->Caption=s;Form2->Label4->Caption=d; Form2->ShowModal(); delete Form2;}