Use VB to establish a detailed process of DCOM server and client applications (2)

zhaozj2021-02-17  61

Use VB to establish a detailed process of DCOM server and client applications (2)

This section describes how to establish DCOM client applications, and their precautions. (I am using the Western VB6)

1. Open VB, click "New Project" in the "File" menu, select "Standard EXE" and click OK.

2. On the Project menu, click References.

3. Click "Browse", select "C: /DCOMDEMO/Server/ProdComDemoServer.exe", click OK, and select this reference.

4. Insert a module in the project, place two CommandButton, two TextBox, and three Label to Form1. Set the following properties:

Control Name Property Value ---------------------------------------------- -------------------- Module Module1 Name ModdcomDemoClient

Form Form1 Name frmdcomDemoClient Caption DCOM DEMO - Client

CommandButton Command1 Name CmdServertime Caption & Get Server Time

Command2 Name CmdcomputenumBers Caption & Compute Numbers

Text Box Text1 Name TxtX Tabstop True TabIndex 0

Text2 name txty tabstop True TabINDEX 1

Label Label1 Name LblansweraD Label2 Name Lblanswersubtract Label3 Name LblServertime Note: Don't give the project now, that is, the name is still "Project1" 5. Copying the code to the module, (not Form1):

Option expedition

Public Osterver AS New _PRODCOMDEMOSERVER.CLSDCOMDEMOSERVER6. Copy as follows code to the FrMDComDemoClient code window:

Option Explicit Private Sub Form_Load () 'Sets the initialization value of the text box. TXTX.Text = "1" txty.text = "2" End Sub

Private sub txtx_gotfocus () txtx.selstart = 0 txtx.sellength = len (txtx.text) end Sub

PRIVATE SUB TXTY_GOTFOCUS () TXTY.SELSTART = 0 TXTY.SELLENGTH = LEN (TXTY.TEX) End Sub

Private Sub CMDServertime_Click () 'Gets the server's program and displays the return value in the lblservertime tab. LBLServertime.caption = oserver.servertime End Sub

Private Sub cmdComputeNumbers_Click () lblAnswerAdd.Caption = oServer.AddNumbers _ (CInt (txtX.Text), CInt (txtY.Text)) lblAnswerSubtract.Caption = oServer.SubtractNumbers _ (CInt (txtX.Text), CInt (txtY.Text) ) End Sub

Private Sub Form_Queryunload (Cancel AS Integer, UnloadMode AS _ Integer

Set oserver = Nothing end SUB

7. On the Project menu, click "Project1 Properties."

8. Click "General" to set the following properties:

Project Type: Standard EXE

Startup Object: frMdcomDemoClient

Project Description: DCOM DEMO PROJECT - Client

9. Click "Make" to set the following properties:

Application Title: ProdcomDemDemoClient

10. Click "Compile" to set the following properties:

Compile to p-code:

11. Click "OK"

12. On the "File" menu, click Save Project AS, save the file name as described below:

Directory FileName Extension ---------------------------------------------- ------------------ C: / DCOMDEMO / CLIENT MODULE MODDCOMDEMOCLIENT .BAS FORM1 FRMDCOMDEMOCLIENT .FRM Project Product PRODCOMDEMOCLIENT .VBP13. Press the "F5" button to test client applications

14. Test completed, in the File menu, click Make ProdcomDemoClient.exe.

15. Save the generated EXE file to C: / DCOMDEMO / CLIENT

16. Turn off the client and server application.

转载请注明原文地址:https://www.9cbs.com/read-31193.html

New Post(0)