Board index » cppbuilder » huge problem: class methods = ????

huge problem: class methods = ????


2005-03-13 02:15:09 AM
cppbuilder102
hi,
I have an application which AV's on me.
It is quite big so i cant post the code, ive been debugging on it for days -
and have seen something which i really cant understand.
The program is an EXE file, which dynamically loads DLL's - and the DLL has
an exported class - based on similar approach as in this thread:
groups.google.dk/groups&lr=&threadm=3e84190d%40newsgroups.borland.com&rnum=1&prev=/groups%3Fq%3Dwww.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20562300.html%26hl%3Dda%26lr%3D%26selm%3D3e84190d%2540newsgroups.borland.com%26rnum%3D1
Anyway it is working okay - normally, there is some issues though - and one
of the ive seen in my debugging, is inspecting the class pointer to the DLL
class.
When the AV comes, i can see that the class has all its variables and its
own classes initiated fine, but the memberfunctions is all: ?????? (which
means they dont have a memoryaddress - somehow not created ?).
Which ofcourse creates the AV, because the program is calling a function
which doesnt have a memory address.
The mysterious part is that it is only happening sometimes, its not
everytime the code is run - in my testing im loading, and reloading the DLL
continously.
What i suspect is that somewhere in the routine where i load the DLL it goes
wrong:
hLibrary = (HINSTANCE)::LoadLibrary( "line.dll" );
if (hLibrary!=NULL)
{
getclassplugin = (GETCLASSPLUGIN) GetProcAddress( hLibrary,
"_LineGetClass" );
setclassplugin = (SETCLASSPLUGIN) GetProcAddress( hLibrary,
"_LineSetClass" );
setclassplugin( (long)( this ) );
if (getclassplugin!=NULL)
{
lineDLL = NULL;
getclassplugin( &lineDLL );
if (lineDLL != NULL)
{
lineDLL->Create();
LineLoaded ( true );
}
}
}
As you can see ive tried to protect myself by checking on NULL's - but they
are always != NULL, so it should be alright - but apparently something goes
wrong.
Anyway - do any of you know how a class can be initiated with variables, and
class inside the variable segment - but memberfunctions arent created ?
Really hope you can help here :(
 
 

Re:huge problem: class methods = ????

One thing I see:
Quote
hLibrary = (HINSTANCE)::LoadLibrary( "line.dll" );
if (hLibrary!=NULL)
{
getclassplugin = (GETCLASSPLUGIN) GetProcAddress( hLibrary,
"_LineGetClass" );
setclassplugin = (SETCLASSPLUGIN) GetProcAddress( hLibrary,
"_LineSetClass" );
setclassplugin( (long)( this ) ); <====HERE
if (getclassplugin!=NULL)
Used without checking for NULL.
. Ed
Quote
infernal wrote in message
news: XXXX@XXXXX.COM ...

I have an application which AV's on me.

It is quite big so i cant post the code, ive been debugging on it
for days - and have seen something which i really cant understand.

The program is an EXE file, which dynamically loads DLL's - and the
DLL has an exported class - based on similar approach as in this
thread:

groups.google.dk/groups&lr=&threadm=3e84190d%40newsgroups.borland.com&rnum=1&prev=/groups%3Fq%3Dwww.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20562300.html%26hl%3Dda%26lr%3D%26selm%3D3e84190d%2540newsgroups.borland.com%26rnum%3D1

Anyway it is working okay - normally, there is some issues though -
and one of the ive seen in my debugging, is inspecting the class
pointer to the DLL class.

When the AV comes, i can see that the class has all its variables
and its own classes initiated fine, but the memberfunctions is all:
?????? (which means they dont have a memoryaddress - somehow not
created ?).

Which ofcourse creates the AV, because the program is calling a
function which doesnt have a memory address.

The mysterious part is that it is only happening sometimes, its not
everytime the code is run - in my testing im loading, and reloading
the DLL continously.

What i suspect is that somewhere in the routine where i load the DLL
it goes wrong:


hLibrary = (HINSTANCE)::LoadLibrary( "line.dll" );
if (hLibrary!=NULL)
{
getclassplugin = (GETCLASSPLUGIN) GetProcAddress( hLibrary,
"_LineGetClass" );
setclassplugin = (SETCLASSPLUGIN) GetProcAddress( hLibrary,
"_LineSetClass" );
setclassplugin( (long)( this ) );
if (getclassplugin!=NULL)
{
lineDLL = NULL;
getclassplugin( &lineDLL );
if (lineDLL != NULL)
{
lineDLL->Create();
LineLoaded ( true );
}
}
}

As you can see ive tried to protect myself by checking on NULL's -
but they are always != NULL, so it should be alright - but
apparently something goes wrong.

Anyway - do any of you know how a class can be initiated with
variables, and class inside the variable segment - but
memberfunctions arent created ?

Really hope you can help here :(
 

Re:huge problem: class methods = ????

Hi Ed,
Youre right - i didnt test setclassplugin pointer for NULL.
This still didnt fixed it though - and breakpointing it shows that i never
get a setclassplugin which is NULL :(
Im very puzzled about this class which dont have their memberfunctions
allocated - im looking into using the Win32 function:
FBadReadPtr() to check the areas where i get the AV - but in the case of the
memberfunctions i cant use it (cant get an address of a function apparently)
do you know how to ?
"Ed Mulroy [TeamB]" < XXXX@XXXXX.COM >skrev i en meddelelse
Quote
One thing I see:

>hLibrary = (HINSTANCE)::LoadLibrary( "line.dll" );
>if (hLibrary!=NULL)
>{
>getclassplugin = (GETCLASSPLUGIN) GetProcAddress( hLibrary,
>"_LineGetClass" );
>setclassplugin = (SETCLASSPLUGIN) GetProcAddress( hLibrary,
>"_LineSetClass" );
>setclassplugin( (long)( this ) ); <====HERE
>if (getclassplugin!=NULL)

Used without checking for NULL.

. Ed

 

{smallsort}

Re:huge problem: class methods = ????

think ive solved the problem - i did 2 freelibrary before doing
loadlibrary() when i reloaded the DLL, which i strongly suspect would mess
up my referencecount - thereby the breakdowns ive experineced.
Been running my test for 30 minutes now on huge load, with no problems -
with that load it wasnt able to run 10 seconds before :)
12 hours of debugging today :( - but now its all worth it :)