⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sendcmddlg.cpp

📁 Get Firmware and IMEI from HS
💻 CPP
字号:
// SendCMDDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SendCMD.h"
#include "SendCMDDlg.h"
#include "Ril.h"
//#include <commctrl.h>
#include <aygshell.h>
//#include <sipapi.h>

#include <Shellapi.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSendCMDDlg dialog

CSendCMDDlg::CSendCMDDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSendCMDDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSendCMDDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CSendCMDDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSendCMDDlg)
	DDX_Control(pDX, IDC_EDIT_IMEI, m_ceditIMEI);
	DDX_Control(pDX, IDC_EDIT_RESPONSE, m_ceditResponse);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSendCMDDlg, CDialog)
	//{{AFX_MSG_MAP(CSendCMDDlg)
	ON_BN_CLICKED(IDC_BUTTON_SEND, OnButtonSend)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


HRIL g_hRil;
SIMRILRESULT g_srr;

/////////////////////////////////////////////////////////////////////////////
// CSendCMDDlg message handlers

BOOL CSendCMDDlg::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
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	// TODO: Add extra initialization here
	//=========================================================================
	memset(&g_srr, 0, sizeof(g_srr));
	//=========================================================================
	return TRUE;  // return TRUE  unless you set the focus to a control
}

//=========================================================================
void WaitForRilResult()
{
    DWORD dwWait;

    if (SUCCEEDED(g_srr.hrID))
    {
        dwWait = WaitForSingleObject(g_srr.hEvent, 5000);
        if (dwWait == WAIT_TIMEOUT)
        {
            // Whoa!  We timed out!  Clean up this memory
            //DEBUGMSG(ZONE_ERROR, (TEXT("Timed out while waiting on RIL call!\r\n")));
			//m_ceditResponse.SetWindowText(L"Timed out while waiting on RIL call!");
            g_srr.hrID = E_FAIL;
        }
    }
}

void ResultProc(DWORD dwResultCode, HRESULT /* hrCommandID */, const void* pData, DWORD dwDataSize, DWORD dwParam)
{
    delete g_srr.pData;

    if (MAX_BUFFER_ALLOCATION > dwDataSize)
    {
        g_srr.pData = new BYTE[dwDataSize];
    }
    else 
    {
        // Incoming buffer size from notification is way too big
        // and may cause problems.
        ASSERT(FALSE);
        g_srr.pData = NULL;
    }
    
    if (g_srr.pData)
    {
        g_srr.dwResultCode = dwResultCode;
        g_srr.dwDataSize = dwDataSize;
        memcpy(g_srr.pData, (LPBYTE) pData, dwDataSize);
    }
    else
    {
        // Out of memory
        g_srr.hrID = E_OUTOFMEMORY;
    }

    SetEvent(g_srr.hEvent);

}
//=========================================================================

void CSendCMDDlg::OnButtonSend() 
{
	// TODO: Add your control notification handler code here
	HRESULT hr = S_OK;
	HRIL m_hRil;
	WCHAR wedit[64];  // To cache the edit box contents
	
	m_ceditResponse.SetWindowText(L"        Please Wait...");

	//=========================================================================
	// Create an event to use with RIL commands
    g_srr.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
    if (!g_srr.hEvent)
    {
        hr = E_FAIL;
        goto Exit;
    }
	hr = RIL_Initialize(1, ResultProc, NULL, 0, (DWORD) this, &m_hRil);
    if (FAILED(hr))
    {
        // Can't do much if RIL couldn't initialize
        MessageBox(L"Couldn't initialize RIL!", L"Error...", MB_OK|MB_SETFOREGROUND|MB_ICONSTOP);
        hr = E_FAIL;
        goto Exit;
    }
	//m_ceditResponse.SetWindowText(L"RIL Initial ok");

	MAKESYNCCALL(RIL_GetEquipmentInfo(m_hRil));

    if (ISRESULTANDDATAOK())
	{
		memset(wedit, NULL, 64);  //erren : to fix response edit control display to much chars when cmd is longer than response...
		// Get Firmware version from structure
		mbstowcs(wedit, (PCHAR)(((RILEQUIPMENTINFO*)(g_srr.pData))->szRevision), MAXLENGTH_EQUIPINFO); 
		m_ceditResponse.SetWindowText(wedit);
		// Get IMEI number from structure
		memset(wedit, NULL, 64);
		mbstowcs(wedit, (PCHAR)(((RILEQUIPMENTINFO*)(g_srr.pData))->szSerialNumber), MAXLENGTH_EQUIPINFO); 
		m_ceditIMEI.SetWindowText(wedit);
		//MessageBox(TEXT("Call RIL_DevSpecific OK!"),TEXT("OK..."), (MB_OK|MB_SETFOREGROUND|MB_ICONINFORMATION));
	}
	else if (ISRESULTOK())
	{
		m_ceditResponse.SetWindowText(L"OK");
		//NKDbgPrintfW(L"g_srr.dwDataSize=%d, g_srr.pData=%x\r\n", g_srr.dwDataSize, g_srr.pData);
	}
	else if (ISRESULTERROR())
	{
		m_ceditResponse.SetWindowText(L"ERROR");
	}
	else
	{
		m_ceditResponse.SetWindowText(L"          Failed!");
		MessageBox(L"Call RIL API Failed!\r\nPlease retry!",L"Error...",MB_OK|MB_SETFOREGROUND|MB_ICONSTOP);
		m_ceditResponse.SetWindowText(L" ");
	}

Exit:
    if (m_hRil)
    {
        RIL_Deinitialize(m_hRil);
        m_hRil = NULL;
    }
	//=========================================================================
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -