Click here to Skip to main content
15,881,173 members
Articles / Desktop Programming / ATL

Understanding The COM Single-Threaded Apartment Part 1

Rate me:
Please Sign up or sign in to vote.
4.95/5 (206 votes)
6 Jan 2005CPOL49 min read 841.4K   4.9K   442  
Learn the fundamental principles of the COM Single-Threaded Apartment Model by code examples.
VERSION 5.00
Begin VB.Form FormMain 
   Caption         =   "Form Main"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command_DoLengthyFunction 
      Caption         =   "Do Lengthy Function"
      Height          =   495
      Left            =   240
      TabIndex        =   0
      Top             =   480
      Width           =   3975
   End
End
Attribute VB_Name = "FormMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim WithEvents SimpleCOMObject1Obj As SimpleCOMObject1
Attribute SimpleCOMObject1Obj.VB_VarHelpID = -1


Private Sub Command_DoLengthyFunction_Click()
  SimpleCOMObject1Obj.DoLengthyFunction 5000
End Sub

Private Sub Form_Load()
  Set SimpleCOMObject1Obj = New SimpleCOMObject1
  
  SimpleCOMObject1Obj.Initialize
End Sub

Private Sub Form_Terminate()
  SimpleCOMObject1Obj.Uninitialize
End Sub

Private Sub SimpleCOMObject1Obj_LengthyFunctionCompleted(ByVal lStatus As Long)
  Dim strMessage As String
  
  strMessage = "Lengthy Function Completed. Status : " & Str$(lStatus)
  
  MsgBox strMessage
End Sub

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Systems Engineer NEC
Singapore Singapore
Lim Bio Liong is a Specialist at a leading Software House in Singapore.

Bio has been in software development for over 10 years. He specialises in C/C++ programming and Windows software development.

Bio has also done device-driver development and enjoys low-level programming. Bio has recently picked up C# programming and has been researching in this area.

Comments and Discussions