Build SO step by step.docx
《Build SO step by step.docx》由会员分享,可在线阅读,更多相关《Build SO step by step.docx(12页珍藏版)》请在冰豆网上搜索。
BuildSOstepbystep
BuildOPOSServiceObejct(SO)StepbyStep
TonyChing
Email:
TonyChing@id-
March8,2005
Whoshouldreadthisdocument?
ThepersonwhodeveloptheOPOSSOwithVisualC++forthenewdeviceshouldreadthisfile.
ThisdocumentdescribethecommonstepstobuildaSOprojectindetails.YoucanfollowittobuildaSOprojectarchitectureforanydevice.PINPadSOistheexamplehere.Youcandoitforanyotherdevicewithalittlechange.
ThisdocumentisNOTafiledescribingOPOS,alsoNOTafileforMicrosoftCOM/ActiveXControl
Beforereadingthisdoc,youshouldmakefamilywithVC++6.0,somebasicknowledgeofMicrosoftCOM/ActiveXControl.
Platformintheexample:
MSCCCO,VisualC++6.0,WindowsXP
STEP1:
Download
DownloadControlObject(CO)implemetionfrom
Ihavedownloadthethreefilesfor1.7.001.Thethirdone,SourceCodeandDataFiles,isveryusefulinthedevelopingdebug.Stronglyrecommendyoudownloadit.
STEP2:
Install
InstalltheOPOSCCO.Selectadirectoryandinstall“CCORuntime”and“CCOSourceCodeandDataFiles”.
STEP3:
MakeCCOprojectwork
ThereisVisualC++Workspaceinthesubdirectory,“\source”.Makeitrun.
Itmayencountersomefilepositionerrorswhenrunningtheproject.Findthecorrectfilespositionandmakesureitbuildanew.OCXfileinthe“Source\OCX\Debug”.Hereisscreenimage.
STEP4:
RegisterCOOCX
RegisterthenewOCX.Commandis:
>regsvr32xxxx.ocx
STEP5:
CreateClientApplication
BuildanormaldialogapplicationastheCOclient.
Thesimplerelationamongclientapplication,CO,ServiceObject(SO)isthatclientcallCOmethod,thenCOcallSOmethod.SoyouneedaclientapplicationfordebugSO.
Step5.0:
AddOPOSincludingfilestotheclientproject
Opos.h
OposPpad.h
Addingdifferentfilesintheotherdevices.
Step5.1:
5.1.0AddtheOCXtotheclientprojectfromthemenu:
Project/AddtoProject/ComonentsandControls
5.1.1theninserttherightActiveXControl.
step5.2
5.2.0InsertaOPOSCOtothedialog.
5.2.1Insertabuttontothedialog.Asfollowing:
5.2.2AddamembervariablefortheOPOScontrol.
Tohere,theclientisready.
STEP6.CreateSO
CreateanewMFCAppWizarDLLProject.
Checkthe“Automation”inthestep1of1.
Step6.0
AddCOclassfromaTLBfilewithMFCClassWizard.
ThisTLBfilelocateinthedirectory“\Source\zPINPad”inthisexample.
thisCOclassisusedwhenSOfiretheEvent.
Step6.1Addinterface.
WithClassWizard,add“newclass”derivedfromCCmdTarget,checkthe“CreateabelbytypeID”
Nowyougetanewclassandainterface.InthisexampletheyareIDTPINPad,IIDTPINPad.
NOTE:
ID:
PINPadSO.IDTPINPad
Youspecifyit,andthisIDistheregisteritemvalue,detailsseeSTEP6.4
6.2Addmethodsandproperties
Addmethodsfortheinterfaceaccordingthespecification.
Makeitrun,andmakesureproduceaDLLandTLBfileinthedebugdirectory.
6.3RegistertheSO.
Commandis:
>Regsvr32pinPadSO2.dll
6.4AddOPOSRegisterItemforSO
[HKEY_LOCAL_MACHINE\SOFTWARE\OLEforRetail\ServiceOPOS\PINPad\idtPINPad]
""="pinPadSO2.idtPinPad"
Copyabovetwolinesintoafile,andsaveas*.regfile,thenregisterit.
NOTE:
Theusingofthisregisteritem
WhenclientcallCO.OpenmethodwithDeviceNmae,hereis“idtPINPad”.Thismethodquerytheregisteritem:
idtPINPad,getthevalue“pinPadSO2.idtPinPad”,thisistheIDspecifiedatSTEP6.1,andthenconvertthisIDtoSOCOMGUID.ThencreateSOinstancewiththisGUID.
step6.3registerSOCOM.Andtheregisteritemaddedinthestep6.4letCOlearntheSOID.
STEP7DebugSO
It’sagoodideathataddclientapplicationproject,COproject,SOprojectintooneWorkSpace.
Backtotheclientdialogapplication.
Addfollowingcodesinthebuttonclickmessagehandlefunction
voidCTestPINPadDlg:
:
OnButOpen()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
intres=m_coPOSPINPad.Open(_T("idtPINPad"));
TRACE("COopenreturncode:
%d\n",res);
if(res!
=OPOS_SUCCESS){
intores=m_coPOSPINPad.GetOpenResult();
TRACE("Openresultcode:
%d\n",ores);
}
}
NotetheparameterofOpenmethod,“idtPINPad”istheregisternamespecifiedatSTEP6.4
STEP8:
ImplementSO.
RundebugintheSOprojectandexecutetheclientdialogapplication.
Congratulation!
IfitcanbeinterruptedintheSOmethodOpenServiceintheDEBUGmode.
ThismeanstheSOinterfaceisready.TherestworkisjustfulfillingthemethodsoftheSOinterface.
OneTip:
Maybe,thefirsttroubleforanewOPOSdeveloperisthatoneormorespecialSOinterface’smethodsarelost.GetAmountandSetAmountarelostinmyPINPadproject.TheCO.Openreturn104(OPOS_E_NOSERVICE)andopenResultis305(OPOS_OR_BADIF).ButIhavenoideaofwhichmethodislost.SoIdebugthePINPadCO.Openmethod.ThefollowingisasectioncoderofOpen.Thearrays_SOMethodNamescontainallthespecifiedmethodnamesthatarerequested.
TheCO.OpenmethodcheckallSOmethods,ifanySOmehthodrequestedlost,CO.Openfailed.
//GetthedispatchIDsforthemethodssupportedbytheServiceObject.
//Stopwhenwecan'tgetoneorwhenallareacquired.
intnMethodCount=0;
while(s_SOMethodNames[nMethodCount]!
=0)
{
_CWNCCMN(s_SOMethodNames[nMethodCount]);//Initforconversion.
OLECHAR*pMN=MN;//Assignpointer,convertingtowideifneeded.
if(S_OK!
=
_pService->GetIDsOfNames(
IID_NULL,&pMN,1,LOCALE_SYSTEM_DEFAULT,&_DispIDs[nMethodCount])
)
{
//Iffailed,dospecialcases:
//-IfwefailedthenewerCloseService,thentryClosebeforefailing.
if(nMethodCount==nDICloseService)
pMN=L"Close";
//-IfwefailedthenewerCOM-friendlynameClaimDeviceorReleaseDevice,
//thentrytheoriginalnameClaimorReleasebeforefailing.
elseif(nMethodCount==nDIClaimDevice)
pMN=L"Claim";
elseif(nMethodCount==nDIReleaseDevice)
pMN=L"Release";
else//Ifnotspecialcase,
break;//stop.
if(S_OK!
=
_pService->GetIDsOfNames(
IID_NULL,&pMN,1,LOCALE_SYSTEM_DEFAULT,&_DispIDs[nMethodCount])
)
break;//Ifspecialcasebutstillnotfound,stop.
}
nMethodCount++;
}
ENDofFILE