user191582
user191582

Reputation: 23

Problem with method defined in VC++ header file

I have a class in a DLL that's used in many other DLLs and EXEs. It has a couple of methods defined in the include file (i.e. the method body is in the .h file) that's included in the other binaries. One of them is giving me fits: int GetVersion() { return nVersion; }.

It is always returning -842150451, but when I run in the debugger and look at the class member variables, nVersion is 100.

Any ideas as to how to debug this problem? I am really stuck.

(Note: This has been working fine for a decade! But now we are moving our code from VC6.0 to VS2005, and it has not been smooth...)

Upvotes: 0

Views: 200

Answers (3)

Jason D
Jason D

Reputation: 2303

So if I follow you you've got the equivalent of following going on:

clas=new MyClass();
// some other code executes

clas->SetVersion(100);
/// some other code executes...
/// one line before, nVersion is fine.
int n=clas->GetVersion(); ///< this is where it all goes wrong

(I would have posted a comment however it doesn't format the code)

I'm also assuming that you're sure that the pointer for clas isn't somehow getting corrupted yet pointed to readable/executable memory. (That would hose things a lot)

As for tools to help you debug this, try using a memory profiling tool such as Compuware DevPartner memory analyzer. Others to look into include Purify, Insure++ (which I've also used, and is more powerful, but harder to use)

These tools tend to quickly alert you to easy to make, but hard to find memory errors.

Upvotes: 0

David Feurle
David Feurle

Reputation: 2787

I had a similar problem related to the not defined initialization order with static variables.

Upvotes: 1

sean e
sean e

Reputation: 11925

That value in hex looks like 0xCDCDCDCD which is normally uninitialized memory in a debug build. Are you sure nVersion is initialized?

Upvotes: 3

Related Questions