470,849 Members | 1,228 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

Trouble with heap after call of DLL method

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

May 11 '06 #1
2 1693
bellerophon wrote:
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-lit...t.html#faq-5.9

Cheers! --M

May 11 '06 #2
>
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-lit...t.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!

May 11 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Kevin Grigorenko | last post: by
2 posts views Thread by Riley DeWiley | last post: by
3 posts views Thread by nahur | last post: by
24 posts views Thread by arcticool | last post: by
16 posts views Thread by sarathy | last post: by
1 post views Thread by Chris Mullins | last post: by
reply views Thread by JosAH | last post: by
3 posts views Thread by emer.kurbegovic | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.