1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  3. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  4. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

MMF Sample code

Discussion in 'New users start here - FAQ' started by TooToo, Dec 3, 2009.

  1. TooToo

    TooToo New Member

    Joined:
    Dec 2, 2009
    Messages:
    7
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Can anyone tell me if there is a sample source code for reading MMF?
    i am not sure how can i read the the injector(using nolimit roller coaster) vaule to be pass into my application.

    thanks
    Too Too :sos:
  2. FAG

    FAG New Member

    Joined:
    Apr 2, 2009
    Messages:
    35
    Occupation:
    Perm/Russia
    Balance:
    413Coins
    Ratings:
    +0 / 0 / -0
    mmf.h
    Code:
    #ifndef _DEF_MMF
    #define _DEF_MMF
    
    #include <windows.h>
    
    namespace MMF {
    
    template < class T >
    class tReadOnly {
    public:
      tReadOnly( const char* name ) : m_hFile( NULL ), m_hView( NULL ), m_Name( name ) {}
     ~tReadOnly() {
        Release();
      }
    
      typedef T type_t;
    
      bool IsValid() const {
        if( m_hView ) return true;
        m_hFile = ::OpenFileMapping( FILE_MAP_READ, FALSE, m_Name );
        if( !m_hFile ) return false;
        if( m_hView = ::MapViewOfFile( m_hFile, FILE_MAP_READ, 0, 0, 0 ) ) {
          return true;
        }
        ::CloseHandle( m_hFile ); 
        m_hFile = NULL;
        return false;
      }
      
      void Release() {
        if( m_hView ) {
          ::UnmapViewOfFile( m_hView );
          m_hView = NULL;
        }
        if( m_hFile ) {
          ::CloseHandle( m_hFile );
          m_hFile = NULL;
        }
      }
      
      const T* get() const {
        return ( IsValid() ? (const T*)m_hView : NULL );
      }
    
    private:
      mutable HANDLE m_hFile;
      mutable HANDLE m_hView;
      const char*    m_Name;
    };
    
    
    } // namespace MMF
    
    #endif // _DEF_MMF
    
    
    used
    Code:
    
    struct sBebe{
      int val1;
      float val2;
    };
    
    
    typedef MMF::tReadOnly< sBebe > MMF_t;
    
    MMF_t m_MMF( MMF_FileName );
    
    if( const sBebe *pMMF = m_MMF.get() ) {
      __try {
         sBebe exchangeInfo;
         memcpy( &exchangeInfo, pMMF, sizeof( exchangeInfo ) );
      }
      __except( GetExceptionCode() == EXCEPTION_IN_PAGE_ERROR ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH ) {
        m_MMF.Release();
      }
    }
    
  3. TooToo

    TooToo New Member

    Joined:
    Dec 2, 2009
    Messages:
    7
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    here is my code.
    i am still unable to read out values in the force injector.
    // slotDlg.cpp : implementation file
    //

    #include stdafx.h
    #include slot.h
    #include slotDlg.h
    #include CSharedStruct.h
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif

    #define maxnumberofgaugeslots 40
    // CslotDlg dialog

    typedef struct SLOTSTRUCT
    {
    int slotstarted[maxnumberofgaugeslots];
    int remoteshutdown[maxnumberofgaugeslots];
    int slotdata[maxnumberofgaugeslots];
    int visualaxis[6];
    int positionx;
    int positiony;
    int saveposition[maxnumberofgaugeslots];
    int moveall;
    int sync[maxnumberofgaugeslots];
    } SharedSlotStruct;
    CSharedStruct<SharedSlotStruct> g_SharedSlotData(Global\\xsimgaugeslot);


    CslotDlg::CslotDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CslotDlg::IDD, pParent)
    {
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }

    void CslotDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);


    }

    BEGIN_MESSAGE_MAP(CslotDlg, CDialog)
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    END_MESSAGE_MAP()


    // CslotDlg message handlers

    BOOL CslotDlg::OnInitDialog()
    {
    CDialog::OnInitDialog();

    // 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

    ShowWindow(SW_MINIMIZE);

    // TODO: Add extra initialization here

    return TRUE; // return TRUE unless you set the focus to a control
    }

    // 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 CslotDlg::OnPaint()
    {
    char temp[64];
    sprintf(temp,%d,g_SharedSlotData->slotdata[0]);
    SetDlgItemText(IDC_EDIT1,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[1]);
    SetDlgItemText(IDC_EDIT2,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[2]);
    SetDlgItemText(IDC_EDIT3,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[3]);
    SetDlgItemText(IDC_EDIT4,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[4]);
    SetDlgItemText(IDC_EDIT5,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[5]);
    SetDlgItemText(IDC_EDIT6,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[6]);
    SetDlgItemText(IDC_EDIT7,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[7]);
    SetDlgItemText(IDC_EDIT8,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[8]);
    SetDlgItemText(IDC_EDIT9 ,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[9]);
    SetDlgItemText(IDC_EDIT10,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[10]);
    SetDlgItemText(IDC_EDIT11,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[11]);
    SetDlgItemText(IDC_EDIT12,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[12]);
    SetDlgItemText(IDC_EDIT13,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[13]);
    SetDlgItemText(IDC_EDIT14,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[14]);
    SetDlgItemText(IDC_EDIT15,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[15]);
    SetDlgItemText(IDC_EDIT16,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[16]);
    SetDlgItemText(IDC_EDIT17,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[17]);
    SetDlgItemText(IDC_EDIT18,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[18]);
    SetDlgItemText(IDC_EDIT19,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[19]);
    SetDlgItemText(IDC_EDIT20,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[20]);
    SetDlgItemText(IDC_EDIT21,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[21]);
    SetDlgItemText(IDC_EDIT22,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[22]);
    SetDlgItemText(IDC_EDIT23,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[23]);
    SetDlgItemText(IDC_EDIT24,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[24]);
    SetDlgItemText(IDC_EDIT25,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[25]);
    SetDlgItemText(IDC_EDIT26,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[26]);
    SetDlgItemText(IDC_EDIT27,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[27]);

    SetDlgItemText(IDC_EDIT28,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[28]);
    SetDlgItemText(IDC_EDIT29,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[29]);
    SetDlgItemText(IDC_EDIT30,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[30]);
    SetDlgItemText(IDC_EDIT31,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[31]);
    SetDlgItemText(IDC_EDIT32,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[32]);
    SetDlgItemText(IDC_EDIT33,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[33]);
    SetDlgItemText(IDC_EDIT34,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[34]);
    SetDlgItemText(IDC_EDIT35,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[35]);
    SetDlgItemText(IDC_EDIT36,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[36]);
    SetDlgItemText(IDC_EDIT37,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[37]);
    SetDlgItemText(IDC_EDIT38,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[38]);
    SetDlgItemText(IDC_EDIT39,CA2W(temp));
    sprintf(temp,%d,g_SharedSlotData->slotdata[39]);
    SetDlgItemText(IDC_EDIT40,CA2W(temp));



    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 CslotDlg::OnQueryDragIcon()
    {
    return static_cast<HCURSOR>(m_hIcon);
    }
  4. TooToo

    TooToo New Member

    Joined:
    Dec 2, 2009
    Messages:
    7
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    any sample code?
  5. TooToo

    TooToo New Member

    Joined:
    Dec 2, 2009
    Messages:
    7
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    thanks. i am still unable to read the value. here is my code.
    the read process is not reading anything.
    i have a read fail.
    am i doing something wrong.
    ReadProcessMemory(nlhproc, (LPCVOID)addr1, &A1, sizeof(A1), &rw);
    ReadProcessMemory(nlhproc, (LPCVOID)addr2, &A2, sizeof(A2), &rw);
    ReadProcessMemory(nlhproc, (LPCVOID)addr3, &A3, sizeof(A3), &rw);

    see below on my code.


    // slotDlg.cpp : implementation file
    //

    #include stdafx.h
    #include slot.h
    #include slotDlg.h
    #include CSharedStruct.h
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif
    #define _WIN32_WINNT _WIN32_WINNT_WINXP
    #define maxnumberofgaugeslots 40
    // CslotDlg dialog

    typedef struct SLOTSTRUCT
    {
    int slotstarted[maxnumberofgaugeslots];
    int remoteshutdown[maxnumberofgaugeslots];
    int slotdata[maxnumberofgaugeslots];
    int visualaxis[6];
    int positionx;
    int positiony;
    int saveposition[maxnumberofgaugeslots];
    int moveall;
    int sync[maxnumberofgaugeslots];
    } SharedSlotStruct;
    CSharedStruct<SharedSlotStruct> g_SharedSlotData(Global\\xsimgaugeslot);
    unsigned addr1 = 5919600;
    unsigned addr2 = 5919604;
    unsigned addr3 = 5919608;
    int A1;
    int A2;
    int A3;
    HWND nlhwnd;

    DWORD nlprocid;
    DWORD rw = 0;
    HANDLE nlhproc;
    CString globlalstr;
    CslotDlg::CslotDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CslotDlg::IDD, pParent)
    {
    bool succ;


    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

    nlhwnd = (FindWindow(NULL, CA2W(NoLimitsSimulator)))->GetSafeHwnd();
    if(!nlhwnd)
    globlalstr= Handle not found!;
    if(nlhwnd)
    {
    globlalstr= Handle found! ;

    succ = GetWindowThreadProcessId(nlhwnd, &nlprocid);
    if(!succ)
    globlalstr=Error while trying to receive process ID!;
    if(succ)
    {
    globlalstr=Process ID received! ;
    nlhproc = OpenProcess(PROCESS_VM_READ , FALSE, nlprocid);
    if(!nlhproc)
    globlalstr= Error while trying to open process!;
    if(nlhproc)
    globlalstr= Successfully opened process! ;
    }

    }








    }

    void CslotDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    CloseHandle(nlhproc);

    }

    BEGIN_MESSAGE_MAP(CslotDlg, CDialog)
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    END_MESSAGE_MAP()


    // CslotDlg message handlers

    BOOL CslotDlg::OnInitDialog()
    {
    CDialog::OnInitDialog();

    // 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

    ShowWindow(SW_MINIMIZE);

    // TODO: Add extra initialization here

    return TRUE; // return TRUE unless you set the focus to a control
    }

    // 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 CslotDlg::OnPaint()
    {
    char temp[64];

    if(nlhproc)
    {

    ReadProcessMemory(nlhproc, (LPCVOID)addr1, &A1, sizeof(A1), &rw);
    ReadProcessMemory(nlhproc, (LPCVOID)addr2, &A2, sizeof(A2), &rw);
    ReadProcessMemory(nlhproc, (LPCVOID)addr3, &A3, sizeof(A3), &rw);

    sprintf(temp,%d,A1);
    SetDlgItemText(IDC_EDIT21,CA2W(temp));
    sprintf(temp,%d,A2);
    SetDlgItemText(IDC_EDIT22,CA2W(temp));
    sprintf(temp,%d,A3);
    SetDlgItemText(IDC_EDIT23,CA2W(temp));
    }
    SetDlgItemText(IDC_EDIT40,globlalstr);

    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 CslotDlg::OnQueryDragIcon()
    {
    return static_cast<HCURSOR>(m_hIcon);
    }
  6. TooToo

    TooToo New Member

    Joined:
    Dec 2, 2009
    Messages:
    7
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    hi i gotthe value. but the number look strange! how do i convert it to g?
  7. TooToo

    TooToo New Member

    Joined:
    Dec 2, 2009
    Messages:
    7
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    hi sirnoname:
    i got it ! thanks. here my code.
    // slotDlg.cpp : implementation file
    //

    #include stdafx.h
    #include slot.h
    #include slotDlg.h
    #include CSharedStruct.h
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif
    #define _WIN32_WINNT _WIN32_WINNT_WINXP
    extern CslotDlg dlg;
    // CslotDlg dialog

    unsigned addr1 = 5919600;
    unsigned addr2 = 5919604;
    unsigned addr3 = 5919608;
    int A1;
    int A2;
    int A3;
    HWND nlhwnd;
    #define PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0xfff)

    DWORD nlprocid;
    DWORD rw = 0;
    HANDLE nlhproc;
    CString globlalstr;

    CslotDlg::CslotDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CslotDlg::IDD, pParent)
    {
    bool succ;


    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

    nlhwnd = (FindWindow(NULL, CA2W(NoLimitsSimulator)))->GetSafeHwnd();
    if(!nlhwnd)
    globlalstr= Handle not found!;
    if(nlhwnd)
    {
    globlalstr= Handle found! ;

    succ = GetWindowThreadProcessId(nlhwnd, &nlprocid);
    if(!succ)
    globlalstr=Error while trying to receive process ID!;
    if(succ)
    {
    globlalstr=Process ID received! ;
    nlhproc = OpenProcess(PROCESS_ALL_ACCESS , FALSE, nlprocid);

    if(!nlhproc)
    globlalstr= Error while trying to open process!;
    if(nlhproc)
    globlalstr= Successfully opened process! ;
    }

    }


    }

    void CslotDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);


    }




    BEGIN_MESSAGE_MAP(CslotDlg, CDialog)
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_WM_TIMER()
    END_MESSAGE_MAP()


    // CslotDlg message handlers

    BOOL CslotDlg::OnInitDialog()
    {
    CDialog::OnInitDialog();

    // 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

    ShowWindow(SW_MINIMIZE);

    // TODO: Add extra initialization here
    SetTimer(1,100,0);
    return TRUE; // return TRUE unless you set the focus to a control
    }

    // 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 CslotDlg::OnPaint()
    {
    char temp[64];
    bool succ;
    DWORD oldProtect = 0;
    DWORD numRead = 0;
    if(nlhproc)
    {

    succ =ReadProcessMemory(nlhproc, (LPCVOID)addr1, &A1, sizeof(A1), &rw);
    succ =ReadProcessMemory(nlhproc, (LPCVOID)addr2, &A2, sizeof(A2), &rw);
    succ =ReadProcessMemory(nlhproc, (LPCVOID)addr3, &A3, sizeof(A3), &rw);
    float *ff;
    if (!succ)
    globlalstr= Reading it wrong ;
    ff = (float*)&A1;
    sprintf(temp,vertical %f g,*ff);
    SetDlgItemText(IDC_EDIT21,CA2W(temp));
    ff = (float*)&A2;
    sprintf(temp,latitudal %f g,*ff);
    SetDlgItemText(IDC_EDIT22,CA2W(temp));
    ff = (float*)&A3;
    sprintf(temp,longtitudal %f g,*ff);
    SetDlgItemText(IDC_EDIT23,CA2W(temp));
    }
    //SetDlgItemText(IDC_EDIT40,globlalstr);

    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 CslotDlg::OnQueryDragIcon()
    {
    return static_cast<HCURSOR>(m_hIcon);
    }




    void CslotDlg::OnTimer(UINT_PTR nIDEvent)
    {
    // TODO: Add your message handler code here and/or call default
    this->OnPaint();
    CDialog::OnTimer(nIDEvent);

    }