Trouble with heap after call of DLL method

B

bellerophon

I am having a serious trouble with my pointers in a programm that uses
dll and was hoping that somebody in this group could help me:

I export my DLL classes with declspec(dllexport) and link against them
using the lib-file. I do not use anything but stuff included in the C++
standard libraries (like iostream) so far.

In my calling application I first do

class __declspec(dllimport) Image {
public:
Image();
....

};

and afterwards I do


double * values = new double[9];
double values[0] = 0.0;
....
double values[8] = 0.0;

cout << "DEBUG: values is at address " << values << endl;
Image im();
cout << "DEBUG: deleting at memory address " << values << endl;
delete [] values;

The empty image constructor does nothing, not even initializing the
member variables with standard values. I tried to resimulate the
ever-reoccuring problem under a minimal environment and an in my
opinion an empty member constructor is such.

Now I fail to delete values. The output of the program is:

DEBUG: values is at address 003814C0
DEBUG: deleting at memory address 00381400

Obviously I am either overwriting the pointer to the array or I having
some other heap problem - which is really driving me crazy, since I
can't find the reason for it.
When I am calling a static (exported) function such as
Image::printHelloWorld(); the problem doesn't occur.

If I am initializing values from stack (double values[9]); values[0] is
overwritten after the DLL method call...

Can anybody tell me, what I seem to be missing here?

Thanks in advance
 
M

mlimber

bellerophon said:
I am having a serious trouble with my pointers in a programm that uses
dll and was hoping that somebody in this group could help me:

I export my DLL classes with declspec(dllexport) and link against them
using the lib-file. I do not use anything but stuff included in the C++
standard libraries (like iostream) so far.

In my calling application I first do

class __declspec(dllimport) Image {
public:
Image();
...

};

and afterwards I do


double * values = new double[9];
double values[0] = 0.0;
...
double values[8] = 0.0;

cout << "DEBUG: values is at address " << values << endl;
Image im();

This does not invoke the constructor; it declares a function named "im"
returning an Image and taking no parameters. Thus, it should not invoke
your DLL at all.
cout << "DEBUG: deleting at memory address " << values << endl;
delete [] values;

The empty image constructor does nothing, not even initializing the
member variables with standard values. I tried to resimulate the
ever-reoccuring problem under a minimal environment and an in my
opinion an empty member constructor is such.

Now I fail to delete values. The output of the program is:

DEBUG: values is at address 003814C0
DEBUG: deleting at memory address 00381400

Obviously I am either overwriting the pointer to the array or I having
some other heap problem - which is really driving me crazy, since I
can't find the reason for it.
When I am calling a static (exported) function such as
Image::printHelloWorld(); the problem doesn't occur.

If I am initializing values from stack (double values[9]); values[0] is
overwritten after the DLL method call...

Can anybody tell me, what I seem to be missing here?

Thanks in advance

Show us a minimal but *complete* sample that demonstrates your problem.
If it is a C++ *language* issue, we'll try to help you. If it is a DLL
issue, you'll have to ask the Microsoft folks, as DLLs are off-topic in
this group. For what is on-topic and for some potential groups you
could pursue this in if it's not a language issue, see this FAQ:

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9

Cheers! --M
 
B

bellerophon

This does not invoke the constructor; it declares a function named "im"
returning an Image and taking no parameters. Thus, it should not invoke
your DLL at all.

The brackets () slipped in, I'm sorry (I'm still *this* used to Java) -
in my program I have just used Image im;
Show us a minimal but *complete* sample that demonstrates your problem.
If it is a C++ *language* issue, we'll try to help you. If it is a DLL
issue, you'll have to ask the Microsoft folks, as DLLs are off-topic in
this group. For what is on-topic and for some potential groups you
could pursue this in if it's not a language issue, see this FAQ:

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9

Cheers! --M

Well, probably it's a DLL issue. I'm sorry for posting this off-topic
but I didn't find the groups mentioned in the FAQ in the first place...


Thanks for your help anyways!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top