Board index » cppbuilder » Illegal instruction closing form with class in DLL

Illegal instruction closing form with class in DLL

My project directory is in a ZIP file at www.flash.net/~woerner/closeerror.zip
or use the following to reproduce:

I created a DLL with the following additions to the default DLL in C++Builder4 Enterprise:

__declspec(dllexport) class CPrinters
{
public:
        int H;
        char  *Ver;
               CPrinters();
              ~CPrinters();
        int    JobNo;

Quote
};

CPrinters::CPrinters()
{
    Ver=0;

Quote
}

CPrinters::~CPrinters()
{
Quote
}

I then created a new application.  On it, I put a BitButton which does nothing.  In the form header, I put:
__declspec(dllimport) class CPrinters
{
public:
        int H;
        char  *Ver;
               CPrinters();
              ~CPrinters();
        int    JobNo;

Quote
};

And in the forms public section:
    CPrinters *Prn;

In the Constructor:
    Prn=new CPrinters();

In the Destructor:
    if(Prn!=0)
    {
        delete Prn;
        Prn=0;
    }

Any help would be greatly appreciated.

 

Re:Illegal instruction closing form with class in DLL


Things like this happen when you change the class (add methods or
something). Recompile the DLL and the host app and it should work
again. Until you add more to the class.
To the app, the class is different from the class in the Dll, causing
all sorts of weird effects. Be prepared to run into more trouble if
you stick to exported classes in a dll, I recommend you use normal
C functions for this instead of a class.

--
Martin

------------------------------------------
Sign the Linux driver petition
http://www.libranet.com/petition.html
------------------------------------------

Re:Illegal instruction closing form with class in DLL


Quote
cha...@xs4all.nl (martin) wrote:
>Things like this happen when you change the class (add methods or
>something). Recompile the DLL and the host app and it should work
>again. Until you add more to the class.
>To the app, the class is different from the class in the Dll, causing
>all sorts of weird effects. Be prepared to run into more trouble if
>you stick to exported classes in a dll, I recommend you use normal
>C functions for this instead of a class.

>--
>Martin

>------------------------------------------
>Sign the Linux driver petition
>http://www.libranet.com/petition.html
>------------------------------------------

This is a significantly reduced class and DLL that still exhibits the crash, so more data and functions are immaterial.
The same header (with the exception of an import/export define) is compiled in both DLL and Project.  
I completely rebuild both the DLL and Project to eliminate the possibility of something not being up to date.
Does anyone know why the class is different to the app and DLL?
I will see if taking the class out of the DLL helps.
Thanks...

Other Threads