QuickMark API Examples

About msgapi

This example demonstrates how to develop applications to work with QuickMark.

Note:

Developers should have prior knowledge of concepts about developing mobile applications in Windows Mobile, Symbian S60, or iPhone.

Symbian C++

Top

Found in: \API_Example\SymbianOS\

Step 1: Launch QuickMark for scanning.

New window
void CmsgapiAppUi::StartQuickMark()
{
	//===========================================
	//QuickMark constants UID 
	//S60 2nd Edition: 0x0c5567c0
	//above S60 3rd Edition: 0x20004FFE
	//===========================================
	
	const TInt KQuickmarkUid = 0x20004FFE;
	TUid id( TUid::Uid( KQuickmarkUid ) );
	TUid msgapid(TUid::Uid( _UID3 )); //Client msgapi Uid

	TApaTaskList taskList(CEikonEnv::Static()->WsSession());
	TApaTask task = taskList.FindApp( id );

	if ( task.Exists() ) 
	{
		// Send a Uid to QuickMark that will callback.
		//above S60 3rd Edition: require SwEvent capability.
		_LIT8(params,"");
		task.SendMessage( msgapid, params);
		task.BringToForeground();
	
	}else{
	
		HBufC* param = HBufC::NewLC( 256 );
		param->Des().AppendNum(msgapid.iUid);
		RApaLsSession appArcSession;
		// connect to AppArc server
		User::LeaveIfError(appArcSession.Connect());
		TThreadId idt;
		appArcSession.StartDocument(*param, TUid::Uid(KQuickmarkUid),idt);
		appArcSession.Close();
		CleanupStack::PopAndDestroy(); // param
	}
}
         

Step 2: Handle the result from QuickMark application.

New window
MCoeMessageObserver::TMessageResponse CmsgapiAppUi::HandleMessageL(TUint32 aClientHandleOfTargetWindowGroup, TUid aMessageUid, const TDesC8 &aMessageParameters)
{
	TBuf<1024> iQuickMarkResult;  
	iQuickMarkResult.Zero();

	//convert UTF8 to UCS2
	//The result from quickmark is encoded using UTF8.
	CnvUtfConverter::ConvertToUnicodeFromUtf8(iQuickMarkResult,aMessageParameters);
	
	//TODO: Add your code
	iEikonEnv->InfoWinL( _L("Result"), iQuickMarkResult);

	return MCoeMessageObserver::EMessageHandled;
}
         

Visual C++

Top

Found in: \API_Example\WindowsMobile\msgapi_C++_source.rar

Step 1: QuickMark sends and receives API commands using WM_COPYDATA messages. Use the RegisterWindowMessage method to register the QuickMarkMessengerAPIApplication message.

New window
UINT RM_QuickMarkMessengerAPIApp = 0;  //global
...
RM_QuickMarkMessengerAPIApp = RegisterWindowMessage(TEXT("QuickMarkMessengerAPIApplication"));
         

Step 2:Launch QuickMark for scanning.

New window
void LaunchQuickMark()
{
	//1)To check if QuickMark is installed, in regedit check if the following key exists: HKCU\Software\QuickMark, QuickMarkAppPath . 
	//This key points to the location of the QuickMark.exe file.
	
	TCHAR szQuickMarkApp[MAX_PATH];
	TCHAR temp[1024];	
	CRegKey key;
	HRESULT hr;
	DWORD dwSize = 0;
	TCHAR szQMReg[] = _T("Software\\QuickMark");

	memset(szQuickMarkApp,0,MAX_PATH*sizeof(TCHAR));
	memset(temp,0,1024*sizeof(TCHAR));

	hr = key.Open(HKEY_CURRENT_USER, szQMReg);
	if (hr == ERROR_SUCCESS)
	{
		if (key.QueryStringValue(_T("QuickMarkAppPath"),NULL,&dwSize) == ERROR_SUCCESS)
			key.QueryStringValue(_T("QuickMarkAppPath"), szQuickMarkApp, &dwSize);
	}
	key.Close();

	//2)If the key is not exists, set default application path of QuickMark.
	if (_tcslen(szQuickMarkApp) == 0)
		wsprintf(szQuickMarkApp, L"\\Program Files\\QuickMark\\QuickMark.exe"); //default path
	
	//3)Launch QuickMark.
	HANDLE h = NULL;
	WIN32_FIND_DATA f;
	int checkWin = 0;
	h = FindFirstFile(szQuickMarkApp, &f);
	if(h != INVALID_HANDLE_VALUE)
	{
		SHELLEXECUTEINFO ShExecInfo;
		memset(&ShExecInfo, 0, sizeof(SHELLEXECUTEINFO));
		ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
		ShExecInfo.lpVerb = L"Open";
		ShExecInfo.lpFile =szQuickMarkApp;
		ShExecInfo.lpParameters = L"";
		ShExecInfo.nShow = SW_SHOW;
		ShellExecuteEx(&ShExecInfo);
		Sleep(1000); //wait one second.
	}
	FindClose(h);

	//4)To initiate communication, a client application broadcasts the RM_QuickMarkMessengerAPIApp message, including its window handle as a wParam parameter. 
	//----------------------------------------------
	//parameters: 
	//HWND hWnd: HWND_BROADCAST , all top windows.
	//UINT Msg: A unique message for inter-application communication.
	//WPARAM wParam: Handle to the window whose window procedure will receive the decoded result.
	//LPARAM lParam: Set QuickMark application to 1D or 2D scanning.  (1:1D   2:2D)
	//----------------------------------------------
	int DefaultBarcodeType = 2; //Default is 2D scanning.
	PostMessage(HWND_BROADCAST, RM_QuickMarkMessengerAPIApp, (WPARAM)hwndMain, (LPARAM)DefaultBarcodeType);
}
     

Step 3: Handle the result from QuickMark application.

New window
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message) 
    {
    	...
    	//Receive the result.
    	case WM_COPYDATA:
    		QuickMarkMSG( hWnd, message, wParam, lParam);
			break;
    }
}       
...  
...           
LRESULT QuickMarkMSG( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
	//Show the result.
	//----------------------------------------------
	//STRUCT COPYDATASTRUCT member
	//dwData: unused.
	//lpData:Long pointer to data. The data is a Unicode string.
	//cbData:Specifies the size, in bytes, of the data pointed to by the lpData member.
	//----------------------------------------------
	
	COPYDATASTRUCT* oCopyData;
	oCopyData=(COPYDATASTRUCT *)lParam;
	wchar_t receive[1024];
	wsprintfW(receive,(LPCWSTR)oCopyData->lpData);
	MessageBox(hWnd, receive, TEXT("Result"), MB_OK);
	return 1;
}                               
     

Visual C#

Top

Found in: \API_Example\WindowsMobile\msgapi_C#_source.rar

Step 1: Add using clauses.

New window
using System.Diagnostics;
using System.Runtime.InteropServices;   
using Microsoft.Win32;                  
using System.IO;                        
using Microsoft.WindowsCE.Forms;   //Add a reference: Microsoft.WindowCE.Forms
      

Step 2:QuickMark sends and receives API commands using WM_COPYDATA messages. Use the RegisterWindowMessage method to register the QuickMarkMessengerAPIApplication message.

New window
private UInt32 RM_QuickMarkMessengerAPIApp = 0; //global
...
this.RM_QuickMarkMessengerAPIApp = RegisterWindowMessage("QuickMarkMessengerAPIApplication");
      

Step 3:Launch QuickMark for scanning.

New window
private void LaunchQuickMark()
{
    //1)To check if QuickMark is installed, in regedit check if the following key exists: HKCU\Software\QuickMark, QuickMarkAppPath . 
	//This key points to the location of the QuickMark.exe file.
 	
    String szQuickMarkApp = "";
    RegistryKey QuickMarkKey = Registry.CurrentUser;
    QuickMarkKey = QuickMarkKey.OpenSubKey("Software\\QuickMark", false);
    szQuickMarkApp = QuickMarkKey.GetValue("QuickMarkAppPath").ToString();
    QuickMarkKey.Close();
    
    //2)If the key is not exists, set default application path of QuickMark.
    if (szQuickMarkApp.Length == 0)
        szQuickMarkApp = "\\Program Files\\QuickMark\\QuickMark.exe";

    //3)Launch QuickMark.
    if (File.Exists(szQuickMarkApp))
    {
        //Launch application
        Process P = new Process();
        P.StartInfo.FileName = szQuickMarkApp;
        P.StartInfo.Verb= "Open";
        P.Start();
        P.WaitForExit(1000); //wait 1 second

    //4)To initiate communication, a client application broadcasts the RM_QuickMarkMessengerAPIApp message, including its message window handle as a wParam parameter. 
	//----------------------------------------------
	//parameters: 
	//HWND hWnd: HWND_BROADCAST , all top windows.
	//UINT Msg: A unique message for inter-application communication.
	//WPARAM wParam: Handle to the window whose window procedure will receive the decoded result.
	//LPARAM lParam: Set QuickMark application to 1D or 2D scanning.  (1:1D   2:2D)
	//----------------------------------------------
        int DefaultBarcodeType = 2; //Default is 2D scanning.
        PostMessageW(HWND_BROADCAST, RM_QuickMarkMessengerAPIApp, messageWindow.Hwnd, (System.IntPtr)DefaultBarcodeType);
    }
    else
    {
        MessageBox.Show("QuickMark not found!");
    }
}
      

Step 4:Handle the result from QuickMark application.

New window
private MyMessageWindow messageWindow; 	//Definition
...
this.messageWindow = new MyMessageWindow();
...
...
//Class MyMessageWindow implementation.
internal class MyMessageWindow : MessageWindow
{
    private const int WM_COPYDATA = 0x004A;

    //----------------------------------------------
	//STRUCT COPYDATASTRUCT member
	//dwData: unused.
	//lpData:Long pointer to data. The data is a Unicode string.
	//cbData:Specifies the size, in bytes, of the data pointed to by the lpData member.
	//----------------------------------------------
    public struct COPYDATASTRUCT
    {
        public int dwData;
        public int cbData;
        public IntPtr lpData;
    }

    protected override void WndProc(ref Message msg)
    {
        switch (msg.Msg)
        {
            case WM_COPYDATA:
                 {
                     //Receive the result.
                     string str = GetMsgString(msg.LParam);
                      MessageBox.Show(str,"Result");
                    //TODO:Add your code here to process with the str.
                 }
                break;
        }
        base.WndProc(ref msg);
    }

    public static string GetMsgString(IntPtr lParam)
    {
	  //Get the result.
        if(lParam!=IntPtr.Zero)
        {
            COPYDATASTRUCT st = (COPYDATASTRUCT) Marshal.PtrToStructure(lParam,typeof(COPYDATASTRUCT));
            string str = Marshal.PtrToStringUni(st.lpData);
            return str;
        }
        else
        {
            return null;
        }
    }
}
       

Visual Basic

Top

Found in: \API_Example\WindowsMobile\msgapi_VB_source.rar

Step 1: Add Imports clauses.

New window
Imports System.Diagnostics
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Imports System.IO
Imports Microsoft.WindowsCE.Forms   'Add a Reference: Microsoft.WindowCE.Forms
       

Step 2:QuickMark sends and receives API commands using WM_COPYDATA messages. Use the RegisterWindowMessage method to register the QuickMarkMessengerAPIApplication message.

New window
Private RM_QuickMarkMessengerAPIApp As UInt32 = 0 'global
...
Me.RM_QuickMarkMessengerAPIApp = RegisterWindowMessage("QuickMarkMessengerAPIApplication")
       

Step 3:Launch QuickMark for scanning.

New window
Private Sub LaunchQuickMark()
    '1)To check if QuickMark is installed, in regedit check if the following key exists: HKCU\Software\QuickMark, QuickMarkAppPath.
    'This key points to the location of the QuickMark.exe file.
    
    Dim szQuickMarkApp As String = ""
    Dim QuickMarkKey As RegistryKey = Registry.CurrentUser
    QuickMarkKey = QuickMarkKey.OpenSubKey("Software\QuickMark", False)
    szQuickMarkApp = QuickMarkKey.GetValue("QuickMarkAppPath").ToString()
    QuickMarkKey.Close()

    '2)If the key is not exists, set default application path of QuickMark.
    If szQuickMarkApp.Length = 0 Then
        szQuickMarkApp = "\Program Files\QuickMark\QuickMark.exe"
    End If

    '3):Launch QuickMark.
    If File.Exists(szQuickMarkApp) Then
        'Launch application
        Dim P As New Process()
        P.StartInfo.FileName = szQuickMarkApp
        P.StartInfo.Verb = "Open"
        P.Start()
        P.WaitForExit(1000)
        'wait 1 second
        
    '4)To initiate communication, a client application broadcasts the RM_QuickMarkMessengerAPIApp message, including its window handle as a wParam parameter. 
    '----------------------------------------------
	'parameters: 
    'HWND hWnd: HWND_BROADCAST , all top windows.
    'UINT Msg: A unique message for inter-application communication.
    'WPARAM wParam: Handle to the window whose window procedure will receive the decoded result.
    'LPARAM lParam: Set QuickMark application to 1D or 2D scanning.  (1:1D   2:2D)
	'----------------------------------------------
        Dim DefaultBarcodeType As Integer
        DefaultBarcodeType = 2 'Default is 2D scanning.
        PostMessageW(HWND_BROADCAST, RM_QuickMarkMessengerAPIApp, messageWindow.Hwnd, DefaultBarcodeType)
    Else
        MessageBox.Show("QuickMark not found!")
    End If
End Sub
      

Step 4: Handle the result from QuickMark application.

New window
Private messageWindow As MyMessageWindow 	'Definition
...
Me.messageWindow = New MyMessageWindow()
...
...
'Class MyMessageWindow implementation.
Friend Class MyMessageWindow
    Inherits MessageWindow

    Private Const WM_COPYDATA As Integer = 74
    
    '----------------------------------------------
	'STRUCT COPYDATASTRUCT member
    'dwData:unused.
    'lpData:Long pointer to data. The data is a Unicode string.
    'cbData:Specifies the size, in bytes, of the data pointed to by the lpData member.
	'----------------------------------------------
    Public Structure COPYDATASTRUCT
        Public dwData As Integer
        Public cbData As Integer
        Public lpData As IntPtr
    End Structure

    Protected Overloads Overrides Sub WndProc(ByRef msg As Message)
        Select Case msg.Msg
            Case WM_COPYDATA
            	'Receive the result.
                Dim str As String = GetMsgString(msg.LParam)
                'TODO:Add your code here to process with the str.
                MessageBox.Show(str, "Result")
                Exit Select
        End Select
        MyBase.WndProc(msg)
    End Sub

    Public Shared Function GetMsgString(ByVal lParam As IntPtr) As String
		'Get the result.
        If lParam <> IntPtr.Zero Then
            Dim st As COPYDATASTRUCT = DirectCast(Marshal.PtrToStructure(lParam, GetType(COPYDATASTRUCT)), COPYDATASTRUCT)
            Dim str As String = Marshal.PtrToStringUni(st.lpData)
            Return str
        Else
            Return Nothing
        End If
    End Function
End Class
       
Top