Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5989523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:06:49+00:00 2026-05-22T23:06:49+00:00

I am writing a wrapper class to call _CrtDumpMemoryLeaks() in WPF application. I am

  • 0

I am writing a wrapper class to call _CrtDumpMemoryLeaks() in WPF application. I am loading a C language DLL in the WPF application and would like to see if the there are any memory leaks in the DLL as WPF is acting as a test app for DLL also.

class MemLeak
{
    static int _CRTDBG_ALLOC_MEM_DF   =  0x01;
    static int _CRTDBG_LEAK_CHECK_DF  =  0x20;        
    static int _CRTDBG_MODE_DEBUG     =  0x2;
    static int _CRTDBG_MODE_WNDW      =  0x4;
    static int _CRT_WARN              =  0;
    static int _CRT_ERROR             =  1;
    static int _CRT_ASSERT            =  2;

    [DllImportAttribute("msvcrtd.dll", EntryPoint = "_CrtDumpMemoryLeaks", SetLastError = true)]
    static extern int _CrtDumpMemoryLeaks();

    [DllImportAttribute("msvcrtd.DLL", EntryPoint = "_CrtSetDbgFlag")]
    static extern int _CrtSetDbgFlag(int newFlag);

    [DllImportAttribute("msvcrtd.DLL", EntryPoint = "_CrtSetReportMode")]
    static extern int _CrtSetReportMode(int reportType, int reportMode);

    public static void StartMemLeakLogging()
    {
        _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
        _CrtSetReportMode(_CRT_ERROR | _CRT_WARN | _CRT_ASSERT, _CRTDBG_MODE_DEBUG);
    }

    public static void StopMemLeakLogging()
    {
        _CrtSetReportMode(_CRT_ERROR | _CRT_WARN | _CRT_ASSERT, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_WNDW);
        int i = _CrtDumpMemoryLeaks();
    }
}

I am using Visual Studio 2008 SP1 on Windows XP Professional SP3. Strangely I had to download the msvcrtd.dll file because the system could not find it. After that, just copied it to the debug folder and the application started working. However, I don’t see the memory leak information in the output window during the debugging even if I intentionally allocated memory and not free in the DLL code.

Also, I cannot change the source code of the DLL else would have tried putting these functions in the DLL source code. I tried creating a MFC application and calling DLL functions, the MFC application detects the memory leaks and displays in the output window even if I dont call the _CrtDumpMemoryLeaks() because I think MFC in debug might internally be calling this function but it doesnt work with WPF test app.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:06:49+00:00Added an answer on May 22, 2026 at 11:06 pm

    Got it working. The link below for reference

    http://social.msdn.microsoft.com/Forums/en/clr/thread/484de950-f488-452e-a9bf-b8b4cd2d1f75

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a .NET wrapper class for an existing native class which throws
I'm writing a wrapper class in C# for a USB device (using P/Invoke to
When writing a class to act as a wrapper around a heap-allocated object, I
I'm writing a C# .NET module and I would like to use the provider
I am working on writing a wrapper DLL to interface a communication DLL for
For my CMS application I'm writing a DLL that I will include into my
Is there any way to return a readonly instance of an object? public class
I'm using SQLite to store my data. I'm writing wrapper class, and I want
I'm writing a wrapper class around the V8 engine so that eventually I'll be
I am currently writing an open source wrapper for a COM object. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.