开发者

"Vista-only" heap corruption in a MFC application

开发者 https://www.devze.com 2023-04-07 15:09 出处:网络
Ours is a MFC application, which links to a win32 DLL. When the application invokes this DLL function, the argument "buffer" becomes a "Bad P开发者_Go百科ointer", after entering th

Ours is a MFC application, which links to a win32 DLL. When the application invokes this DLL function, the argument "buffer" becomes a "Bad P开发者_Go百科ointer", after entering the function stack. This results in an application crash.

static MyClass* Instance(string& buffer);

I changed the argument type to "char *", but it only pushes the crash to next statement in the function. How to detect this heap corruption?

Few hints

  • This crash is reproducible, even if I invoke this DLL function from the very start of our application (CWinApp constructor). Could this memory corruption be caused by loading of resources, manifest etc?
  • The crash is ocurring in Vista and Win7, but not in XP.
  • Both these projects were recently migrated from Visual Studio 2002 to VS2008.

Code that invokes the function

CString data = "some string";
string str = data.GetBuffer();
data.ReleaseBuffer();
MyClass *obj = MyClass::Instance(str);


There were two mistakes:

  1. Couple of custom built C++ files were not compiled with MD switch. We had to add -MD to the custom build script to make the CRT consistant with other objects.

  2. There were LNK2005 conflicts between LIBCMT.LIB and MSVCRT.LIB, which were otherwise ignored due to the /FORCE switch. We resolved these conflicts by removing LIBCMT.LIB in Linker->Input

Thanks all for your help.


My guess is this is wrong usage of calling conventions or a CRT mismatch (i go with calling conventions).

Try building a stub DLL with the same function signature (which does nothing) and make it work with your MFC app.

Here's an example...

HTH

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号