精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>C/C++>>动态连接库(.dll, .so)>>DLL问题

主题:DLL问题
发信人: jone_lonne()
整理人: wenbobo(2002-12-19 17:27:02), 站内信件
DLLForm.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "DLLFrom.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
   returnValue=1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::cmdYesClick(TObject *Sender)
{
    returnValue=1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::cmdNoClick(TObject *Sender)
{
    returnValue=2;
}
//---------------------------------------------------------------------------
int _fastcall TForm1::GetReturnValue()
{
    return returnValue;
}
//---------------------------------------------------------------------------
int _stdcall InvokeYesNo()
{
    int returnValue;
    TForm1 *Form1=new TForm1(NULL);
    Form1->ShowModal();
    returnValue=Form1->GetReturnValue() ;
    delete Form1;

    return returnValue;
}
//---------------------------------------------------------------------------

DLLForm.h
//---------------------------------------------------------------------------

#ifndef DLLFromH
#define DLLFromH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
        TButton *cmdYes;
        TButton *cmdNo;
        void __fastcall cmdYesClick(TObject *Sender);
        void __fastcall cmdNoClick(TObject *Sender);
private: // User declarations
        int returnValue;
public: // User declarations
        __fastcall TForm1(TComponent* Owner);
        int _fastcall GetReturnValue();
};
extern "C" __declspec(dllexport) int __stdcall InvokeYesNo();
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

UseVclDLL.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "UseVclDLL.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm2::Button1Click(TObject *Sender)
{
//    int (*InvokeYesNo)();
       HINSTANCE dllHandle=LoadLibrary("VclDLLProject.dll");
    InvokeYesNo=(int(*)())
                 GetProcAddress(dllHandle,"_InvokeYesNo");
    int i=InvokeYesNo();
    if( i=1 )
    ShowMessage("Yes");
    else
    ShowMessage("No");
    FreeLibrary(dllHandle);

}
//-----------------------------------------------------------

调用后总是报Access violation at address 00000000,Read of address 00000000"的错误是为什么?

[关闭][返回]