C DLL ExampleTable of ContentsC# Example
bcParserX for Pocket PC

Math Expression Parser in PocketPC

The bcParserX Math Parser COM Component can be compiled to run on mobile devices under Windows CE (Pocket PC).

There are some wrinkles to iron out before it can be compiled and called:

Compiling the COM Component DLL for Pocket PC

Create an empty Windows CE ATL COM project. Copy the bcParserX source code to that project.

eVC++ 3.0 does not come with STL library, therefore, you need to find an STL implementation written for WINCE (No exceptions, No rtti) to compile with.

eVC++ 4.0 does come with STL and has exception support.

COM on Win CE does not support apartment threaded model. Therefore, in the registry file ‘Parser.rgs’, you need to remove the section that marks the component as APARTMENT threaded. (Component will be single threaded):

InprocServer32 = s '%MODULE%'
{
val ThreadingModel = s 'Apartment'
}

Calling the Component from a Pocket PC Application

If your WinCE project is not already using COM, then you need to initialize COM at the beginning:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{

    if(FAILED(CoInitializeEx(NULL, COINIT_MULTITHREADED ))){

      AfxMessageBox(_T("Could not initialize COM"));
      return -1;

    }

}

Here is what the source code of main frame of a MFC application would look like:

#include "stdafx.h"
#include "WinCETestParser.h"

#include "MainFrm.h"

#include <atlbase.h>
#include <atlcom.h>

//Following two function declarations are missing in WinCE version of ATL.
//otherwise below import does not work.

HRESULT __cdecl _com_dispatch_method(IDispatch * pDisp, DISPID dispid, WORD w, VARTYPE vt, void * pResult, const wchar_t * szFormat, ...);
HRESULT __cdecl _com_issue_errorex(HRESULT _hr1,IUnknown *pthis1, const GUID  refiid1);

#import "bcParser.dll"

 

And you could have the following Evaluate function that calls the component:
(Click on image to enlarge)

webmaster@bestcode.com