DLL里FORM的问题。急在线等。
DLL里的内容
#include <clx.h>
#include <windows.h>
#include "Unit2.h "
#pragma argsused
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved)
{
return 1;
}
//---------------------------------------
extern "C " __declspec(dllexport) void NewForm();
extern "C " __declspec(dllexport) int test2();
void NewForm()
{
Form2 = new TForm2(NULL);
Form2-> ShowModal();
delete Form2;
Form2 = NULL;
}
int test2()
{
return 3;
}
Unit2就是一个新的FORM
我只是把Unit2.h里所有的#include。。。。都注释掉了。
EXE里的内容。
Unittest.cpp
//-----------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unittest.h "
//-----------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm "
TFormtest *Formtest;
HINSTANCE test;
//-----------------------------------
__fastcall TFormtest::TFormtest(TComponent* Owner)
: TForm(Owner)
{
}
//-----------------------------------void __fastcall TFormtest::Button1Click(TObject *Sender)
{
NewForm();
}
//-----------------------------------
void __fastcall TFormtest::Button2Click(TObject *Sender)
{
ShowMessage(IntToStr(test2()));
}
//-----------------------------------
Unittest.h里的内容
//-----------------------------------
#ifndef UnittestH
#define UnittestH
//-----------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//-----------------------------------
class TFormtest : public TForm
{
__published:// IDE-managed Components
TButton *Button1;
TButton *Button2;
void __fastcall Button1Click(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
private:// User declarations
public:// User declarations
__fastcall TFormtest(TComponent* Owner);
};
//-----------------------------------
extern PACKAGE TFormtest *Formtest;
extern "C " __declspec(dllimport) void __cdecl NewForm();
extern "C " __declspec(dllimport) int __cdecl test2();
//-----------------------------------
#endif
编译可以通过。然后在EXE里点BUTTON2也没问题。但是一点BUTTON1就报错。
access violation at address ffffffd8.read of address ffffffd8.
知道的麻烦说下~我的QQ是79623593。如果没时间看的话。发个最简单的程序给我也可以(带原代码。在BCB6下的)。功能只要DLL里有FORM~然后EXE调用并SHOW出来 。
[解决办法]
这个动态库难道不需要LoadLibrary么?关注一下
[解决办法]
例子已经发出。