Build SO step by step.docx

上传人:b****8 文档编号:11008812 上传时间:2023-02-24 格式:DOCX 页数:12 大小:881.14KB
下载 相关 举报
Build SO step by step.docx_第1页
第1页 / 共12页
Build SO step by step.docx_第2页
第2页 / 共12页
Build SO step by step.docx_第3页
第3页 / 共12页
Build SO step by step.docx_第4页
第4页 / 共12页
Build SO step by step.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

Build SO step by step.docx

《Build SO step by step.docx》由会员分享,可在线阅读,更多相关《Build SO step by step.docx(12页珍藏版)》请在冰豆网上搜索。

Build SO step by step.docx

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

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 初中教育 > 学科竞赛

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1