Background
Break News
How to add local font to Tailwind Css and NextJS? - Tutorial Design Pattern? - Blockchain Technology, How to create own Bitcoin virtual currency - Zustand mordern management state - Design Pattern - Flyweight Pattern? - Docker Full training Topic

[Tips] A Simple Way to Generate a Map File in C++

Thursday, 13 August 2015
|
Read: Completed in minutes

[Tips] A Simple Way to Generate a Map File in C++

1. Detailed information on all segments (code, data and other).
2. Link line numbers to code
With MAP file, you can easy to know where is your function, This will be help you easy to do auto game!




Creating a MAP file

Well first of all, you'll need a MAP file. If you don't have one, it will be nearly impossible to find where your application crashed using the crash address. So first, I'll show you how to create a good MAP file. For this, I will create a new project (MAPFILE). You can do the same, or adjust your own project. I create a new project using the Win32 Application option in VC++ 6.0, selecting the 'typical "Hello Word!" application' to keep the size of the MAP file reasonable for explanation.
Once created we need to adjust the project settings for the release version. In the C/C++ tab, select "Line Numbers Only" for Debug Info

A Simple Way to Generate a Map File in C++


Many people forget this, but you'll need this option if you want a good MAP file. This will not affect your release in any way. Next is the Link tab. Here you need to select the "Generate mapfile" option. Also, type the switches /MAPINFO:LINES and /MAPINFO:EXPORTS in the Project Options edit box.

A Simple Way to Generate a Map File in C++


Now, you're ready to compile and link your project. After linking, you will find a .map file in your intermediate directory (together with your exe).

If you using Microsoft Visual Studio 2005, 2008, 2010, 2012, 2015. Right click to projects properties -> choose Linker -> Debugging -> Generate Map File -> Yes (/MAP)

A Simple Way to Generate a Map File in C++


Example:
I have one project, after I gen this code with map file, you can see this


// MouseUtilDlg.cpp : implementation file
  //
  /* ********************************************************
   * Author: Zidane (huuvi168@gmail.com)
   * Last Modified: 2015-08-13
   * *******************************************************/
  
  #include "stdafx.h"
  #include "MouseUtil.h"
  #include "MouseUtilDlg.h"
  
  #ifdef _DEBUG
  #define new DEBUG_NEW
  #endif
  
  // CAboutDlg dialog used for App About
  class CAboutDlg : public CDialog
  {
  public:
      CAboutDlg();
  
      // Dialog Data
      enum { IDD = IDD_ABOUTBOX };
  
      protected:
      virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  
  // Implementation
  protected:
      DECLARE_MESSAGE_MAP()
  
  };
  
  CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  {
  }
  
  void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  {
      CDialog::DoDataExchange(pDX);
  }
  
  BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  END_MESSAGE_MAP()
  
  // CMouseUtilDlg dialog
  
  CMouseUtilDlg::CMouseUtilDlg(CWnd* pParent /*=NULL*/)
      : CDialog(CMouseUtilDlg::IDD, pParent)
  {
      m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  }
  
  void CMouseUtilDlg::DoDataExchange(CDataExchange* pDX)
  {
      CDialog::DoDataExchange(pDX);
  }
  
  BEGIN_MESSAGE_MAP(CMouseUtilDlg, CDialog)
      ON_WM_SYSCOMMAND()
      ON_WM_PAINT()
      ON_WM_QUERYDRAGICON()
      ON_WM_LBUTTONUP()
      //}}AFX_MSG_MAP
  END_MESSAGE_MAP()
  
  // CMouseUtilDlg message handlers
  BOOL CMouseUtilDlg::OnInitDialog()
  {
      CDialog::OnInitDialog();
      // Add "About..." menu item to system menu.
      // IDM_ABOUTBOX must be in the system command range.
      ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
      ASSERT(IDM_ABOUTBOX < 0xF000);
  
      CMenu* pSysMenu = GetSystemMenu(FALSE);
      if (pSysMenu != NULL)
      {
          BOOL bNameValid;
          CString strAboutMenu;
          bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
          ASSERT(bNameValid);
          if (!strAboutMenu.IsEmpty())
          {
              pSysMenu->AppendMenu(MF_SEPARATOR);
              pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
          }
      }
  
      // Set the icon for this dialog.  The framework does this automatically
      //  when the application's main window is not a dialog
      SetIcon(m_hIcon, TRUE);            // Set big icon
      SetIcon(m_hIcon, FALSE);        // Set small icon
  
      // TODO: Add extra initialization here
      return TRUE;  // return TRUE  unless you set the focus to a control
  }
  
  void CMouseUtilDlg::OnSysCommand(UINT nID, LPARAM lParam)
  {
      if ((nID & 0xFFF0) == IDM_ABOUTBOX)
      {
          CAboutDlg dlgAbout;
          dlgAbout.DoModal();
      }
      else
      {
          CDialog::OnSysCommand(nID, lParam);
      }
  }
  
  
  // If you add a minimize button to your dialog, you will need the code below
  //  to draw the icon.  For MFC applications using the document/view model,
  //  this is automatically done for you by the framework.
  
  void CMouseUtilDlg::OnPaint()
  {
      if (IsIconic())
      {
          CPaintDC dc(this); // device context for painting
  
          SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  
          // Center icon in client rectangle
          int cxIcon = GetSystemMetrics(SM_CXICON);
          int cyIcon = GetSystemMetrics(SM_CYICON);
          CRect rect;
          GetClientRect(&rect);
          int x = (rect.Width() - cxIcon + 1) / 2;
          int y = (rect.Height() - cyIcon + 1) / 2;
  
          // Draw the icon
          dc.DrawIcon(x, y, m_hIcon);
      }
      else
      {
          CDialog::OnPaint();
      }
  }
  
  // The system calls this function to obtain the cursor to display while the user drags
  //  the minimized window.
  HCURSOR CMouseUtilDlg::OnQueryDragIcon()
  {
      return static_cast<HCURSOR>(m_hIcon);
  }
  
  void CMouseUtilDlg::OnLButtonUp(UINT nFlags, CPoint point)
  {
      CString csMouseMsg;
      csMouseMsg.Format(L"X %d Y %d", point.x, point.y);
      AfxMessageBox(csMouseMsg);
      CWnd::OnLButtonDown(nFlags, point);
  
  }
  





Here is my map file, If you have this file, you can easy to view all projects data, structure in map file. Let's see

MouseUtil
  Timestamp is 55cc6bde (Thu Aug 13 17:05:18 2015)
  Preferred load address is 00400000
  
   Start         Length     Name                   Class
  
   0001:00000000 005a12fbH .text                   CODE
  
   0001:005a1300 000350daH .text$x                 CODE
  
   0001:005d63e0 00003c7eH .text$yc                CODE
  
   0001:005da060 00001e74H .text$yd                CODE
  
   0002:00000000 00000104H .CRT$XCA                DATA
  
   0002:00000104 0000011cH .CRT$XCC                DATA
  
   0002:00000220 000001f4H .CRT$XCL                DATA
  
   0002:00000414 0000043eH .CRT$XCU                DATA
  
   0002:00000854 00000104H .CRT$XCZ                DATA
  
   0002:00000958 00000104H .CRT$XIA                DATA
  
   0002:00000a5c 0000011cH .CRT$XIC                DATA
  
   0002:00000b78 00000104H .CRT$XIY                DATA
  
   0002:00000c7c 00000104H .CRT$XIZ                DATA
  
   0002:00000d80 00000104H .CRT$XPA                DATA
  
   0002:00000e84 00000109H .CRT$XPX                DATA
  
   0002:00000f90 00000104H .CRT$XPXA               DATA
  
   0002:00001094 00000104H .CRT$XPZ                DATA
  
   0002:00001198 00000104H .CRT$XTA                DATA
  
   0002:0000129c 00000104H .CRT$XTZ                DATA
  
   0002:000013a0 00083191H .rdata                  DATA
  
   0002:00084534 00000173H .rdata$debug            DATA
  
   0002:000846a8 00010963H .rdata$r                DATA
  
   0002:00095010 000032b9H .rdata$sxdata           DATA
  
   0002:000982cc 00000104H .rtc$IAA                DATA
  
   0002:000983d0 00000769H .rtc$IMZ                DATA
  
   0002:00098b3c 00000104H .rtc$IZZ                DATA
  
   0002:00098c40 00000104H .rtc$TAA                DATA
  
   0002:00098d44 00000769H .rtc$TMZ                DATA
  
   0002:000994b0 00000104H .rtc$TZZ                DATA
  
   0002:000995b8 0002ff84H .xdata$x                DATA
  
   0002:000c953c 00000104H ATL$__a                 DATA
  
   0002:000c9640 00000104H ATL$__z                 DATA
  
   0002:000c9744 00000000H .edata                  DATA
  
   0003:00000000 0000a3b2H .data                   DATA
  
   0003:0000a3c0 000084c4H .bss                    DATA
  
   0004:00000000 0000017cH .idata$2                DATA
  
   0004:0000017c 00000014H .idata$3                DATA
  
   0004:00000190 00001480H .idata$4                DATA
  
   0004:00001610 00001480H .idata$5                DATA
  
   0004:00002a90 000046b4H .idata$6                DATA
  
   0005:00000000 00001129H .rsrc$01                DATA
  
   0005:00001130 000185c3H .rsrc$02                DATA
  
  
  
   Address         Publics by Value              Rva+Base       Lib:Object
  
  
  
   0000:00000000       __except_list              00000000     <absolute>
  
   0000:00000a5c       ___safe_se_handler_count   00000a5c     <absolute>
  
   0000:00000000       ___ImageBase               00400000     <linker-defined>
  
   0001:00000370       ??0CMouseUtilApp@@QAE@XZ   00401370 f   MouseUtil.obj
  
   0001:000003d0       ??1CMouseUtilApp@@UAE@XZ   004013d0 f i MouseUtil.obj
  
   0001:00000420       ??1CMouseUtilDlg@@UAE@XZ   00401420 f i MouseUtil.obj
  
   0001:00000470       ??_GCMouseUtilApp@@UAEPAXI@Z 00401470 f i MouseUtil.obj
  
   0001:00000470       ??_ECMouseUtilApp@@UAEPAXI@Z 00401470 f i MouseUtil.obj
  
   0001:000004e0       ?GetApplicationRecoveryParameter@CWinApp@@UAEPAXXZ 004014e0 f i MouseUtil.obj
  
   0001:00000520       ?GetApplicationRecoveryPingInterval@CWinApp@@UAEKXZ 00401520 f i MouseUtil.obj
  
   0001:00000560       ?GetApplicationRestartFlags@CWinApp@@UAEKXZ 00401560 f i MouseUtil.obj
  
   0001:000005a0       ?GetMessageMap@CMouseUtilApp@@MBEPBUAFX_MSGMAP@@XZ 004015a0 f   MouseUtil.obj
  
   0001:000005f0       ?GetThisMessageMap@CMouseUtilApp@@KGPBUAFX_MSGMAP@@XZ 004015f0 f   MouseUtil.obj
  
   0001:00000630       ?InitInstance@CMouseUtilApp@@UAEHXZ 00401630 f   MouseUtil.obj
  
   0001:000007c0       ?LoadCustomState@CWinAppEx@@MAEXXZ 004017c0 f i MouseUtil.obj
  
   0001:00000800       ?OnWorkspaceIdle@CWinAppEx@@UAEHPAVCWnd@@@Z 00401800 f i MouseUtil.obj
  
   0001:00000840       ?PreLoadState@CWinAppEx@@MAEXXZ 00401840 f i MouseUtil.obj
  
   0001:00000880       ?PreSaveState@CWinAppEx@@MAEXXZ 00401880 f i MouseUtil.obj
  
   0001:000008c0       ?ReopenPreviousFilesAtRestart@CWinApp@@UBEHXZ 004018c0 f i MouseUtil.obj
  
  ...
  

Thank you for reading this post. I hope you found it helpful and easy to follow. If you have any feedback or questions about A Simple Way to Generate a Map File in C++ , please share them in the comments below. I would love to hear from you and discuss this topic further
✋✋✋✋  Webzone Tech Tips Zidane, all things tech tips web development  - I am Zidane, See you next time soon ✋✋✋✋

🙇🏼🙇🏼 We Appreciate Your Comments and Suggestions - Webzone, all things Tech Tips web development
Popular Webzone Tech Tips topic maybe you will be like it - by Webzone Tech Tips - Zidane
As a student, I found Blogspot very useful when I joined in 2014. I have been a developer for years . To give back and share what I learned, I started Webzone, a blog with tech tips. You can also search for tech tips zidane on Google and find my helpful posts. Love you all,

I am glad you visited my blog. I hope you find it useful for learning tech tips and webzone tricks. If you have any technical issues, feel free to browse my posts and see if they can help you solve them. You can also leave a comment or contact me if you need more assistance. Here is my blog address: https://learn-tech-tips.blogspot.com.

My blog where I share my passion for web development, webzone design, and tech tips. You will find tutorials on how to build websites from scratch, using hot trends frameworks like nestjs, nextjs, cakephp, devops, docker, and more. You will also learn how to fix common bugs on development, like a mini stackoverflow. Plus, you will discover how to easily learn programming languages such as PHP (CAKEPHP, LARAVEL), C#, C++, Web(HTML, CSS, javascript), and other useful things like Office (Excel, Photoshop). I hope you enjoy my blog and find it helpful for your projects. :)

Thanks and Best Regards!
Follow me on Tiktok @learntechtips and send me a direct message. I will be happy to chat with you.
Webzone - Zidane (huuvi168@gmail.com)
I'm developer, I like code, I like to learn new technology and want to be friend with people for learn each other
I'm a developer who loves coding, learning new technologies, and making friends with people who share the same passion. I have been a full stack developer since 2015, with more than years of experience in web development.
Copyright @2022(November) Version 1.0.0 - By Webzone, all things Tech Tips for Web Development Zidane
https://learn-tech-tips.blogspot.com