You are on page 1of 23

!

" # $
!" ## $ % # & ' "( ) "
## % ' ' "( )
* & + '' , & - '' !"
+ ## ". ' / "( ) 0# 1 2
$ ' . ' 3& & & ". '" 4 .
3& & & "$- " 4 '' # ' !" # %
## & + '' $ " 5' # -
'- ' ' & ' ## "( ) -
# - $ "

5 #* + " '' + # #
## # - "6 7 ## 8' - & $ '
+ $ ' & "( ) ' - # & "( ) ' "6
+ ' ' - ' # "( ) $
# & ' ## " + # $ ' ' #
- !" "( ) ## $
$ # ' ' ## 8- # # "

" ' 5 #* + '' % $ # $ $ 9

• 5 #0 - "( ) -
!" ' "
• + & ## !" # ' 3 54 ' -
5 #0 "
• # ' - ## # "

# # & & 5 #* + & # # +


- ' ' " !" &
' 7 # # # "

# : -% 3 : 4 # ' # -
3 ;4 '' " : # - & :
# & "5 - ; 7# -%
: # "0 !" & -%
- ; & "( ) ". ' + & : - & ##
3 14 ' ' : $
!" ## $ - + "

. $ # 1 - # - )7#
3 - 7#" 7 4" # ' 1 ' 7# #
' !" # "< & $ # 7 $ $
"( ) & - $ 7# & & !"
"5 # ' - '
# ' ' # - $ ' :
# $ "

5 #* + " ' & # ' : # " +


# 7# - 1 & /* $ -
> : # " !" $ #
# ## % + : # "

5 #* + " ' # $ # $ ' &


+9

" 1 & * - 3 >4


' !" ## " ' ' 7 $ '
$ - "( ) * & + $ - #
"( ) "
" $ - 3 >4
% + ' . $ ?/ !" ' "
# "( )
- & "( ) "
=" - ## - & '
- ## # # $ ' '
"
@" # - ## 8 + # + ' # A
' - #
# "

. !" $ # ' # - + #
!" & " $ # ' # !"
$ # $ 35 )4 & " ' 5 /
7# ' # # 8# # $
!" "

# A ' 5 #* + !" ' $ '


> " 3( 9 ##
)7# ) "4

5 #* + " & # #9 " '"


$- --@ B @@" #7"

& # #' ' #


## 3* 4"

=
& & # % # 3* 4"

# ' & 5 #* 5 #0
' ## # $ # & # "

@
5' # ' +
# % "6 + 5 ## % '
## # % # $ - +
& 5 ## % 9

" ' & +' " =">" 6


- 7 3* =4"

! "# $ %

" !5 #0 # % $ # - # " 7
' " # ' ' 1 = / $ # # '
' 1 & '& $ # + 3 C4" 5' ' #

>
- # + + * @"

& "# ' ($

6 & & # # '


' D)7# # 1 2 E #' "

5 #* !" # % # $ # 9

" !5
#* - # % "
" ' !" # % & "
=" "( ) 5 ## % & : # "
@" ; ' & # ' !" # % "
>" 0 5 #* !" # % "

* & $ - # #9 " '"


- $- --!@= @=" #7"

! " #$ %
& "( ) # % - !5 #* - # " # %
' "6
' & + $ - !" - !5 #*
# "

& ' ( $ % )
' 5 # - # % "( ) ' $ -
"( ) " 7# ' !" $
$ # # $ & ## # -
3 ) ' * #
+ 4" ' & 7 # 3F5 #* 3)> _

Public Class InteropForm1


<InteropFormInitializer()> _
Public Sub New(ByVal title As String)
InitializeComponent()

!
Me.Text = title
End Sub

Public Sub New()


InitializeComponent()
End Sub

<InteropFormProperty()> _
Public WriteOnly Property ShowToday() As Boolean
Set(ByVal value As Boolean)
calendar.ShowToday = value
End Set
End Property

<InteropFormMethod()> _
Public Sub SetCalendar(ByVal month As Integer, _
ByVal year As Integer)
calendar.SetDate(New Date(year, month, 1))
End Sub

<InteropFormEvent()> _
Public Event DateChanged As DateChangedEventHandler
Public Delegate Sub DateChangedEventHandler _
(ByVal StartDate As String, ByVal EndDate As String)

Private Sub calendar_DateChanged _


(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.DateRangeEventArgs) _
Handles calendar.DateChanged
RaiseEvent DateChanged(e.Start.ToShortDateString(), _
e.End.ToShortDateString())
End Sub
End Class

4 ' - "

<InteropForm()> _
Public Class InteropForm1
<InteropFormInitializer()> _
Public Sub New(ByVal title As String)
InitializeComponent()
Me.Text = title
End Sub

Public Sub New()


InitializeComponent()
End Sub

<InteropFormProperty()> _
Public WriteOnly Property ShowToday() As Boolean
Set(ByVal value As Boolean)
calendar.ShowToday = value
End Set
End Property

<InteropFormMethod()> _
Public Sub SetCalendar(ByVal month As Integer, _
ByVal year As Integer)
calendar.SetDate(New Date(year, month, 1))
End Sub

<InteropFormEvent()> _
Public Event DateChanged As DateChangedEventHandler
Public Delegate Sub DateChangedEventHandler _
(ByVal StartDate As String, ByVal EndDate As String)

Private Sub calendar_DateChanged _

G
(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.DateRangeEventArgs) _
Handles calendar.DateChanged
RaiseEvent DateChanged(e.Start.ToShortDateString(), _
e.End.ToShortDateString())
End Sub
End Class

, - . +"

* # + ## - ' # # # ' 5 #
- " 9

• / ! 0

• .
• 1$

+ $ ## # # #
$ 3* >4"

$2" $ 5 $ +
3 2" $ 5 +
2" $ 5 ' +
2" $ 5
2" $ 5 $ '
4

*+ $ %
' - # % 5 #* & ## " +
# ' + 3* !4"

5 6

.' $ & ## - # % '


& - : # "

, - * . - ( $ %
' 5 #* !" '
5 #* - # "( ) # % 3* G4"
7 - . 58 3

/ ( $ %
.' $ ' !" 5 #
& 5 #* 3* 4"

' & 7 # 3 4 ' ' 7# # #


$ ' "( ) ## "

B
Private WithEvents frm As _
InteropFormDemo.InteropForm1

Private Sub cmdDisplayForm_Click()


Set frm = New _
InteropFormDemo.InteropForm1
frm.Initialize ("Loaded from VB6")

frm.SetCalendar 7, 2009
frm.ShowToday = False

frm.Show vbModeless
End Sub

Private Sub frm_DateChanged( _


ByVal StartDate As String, _
ByVal EndDate As String)
Label1 = StartDate
Label2 = EndDate
End Sub
, - . 58

) *
# ' - & ' ' 5 #* 9

• !" ' ' - !" ' ' "


• . !" ' & !" ' & +, & $
' H' + H & !" '
"( ) ' + "
• 6 5 #* 5 ' !" " 5' &
7 5' 5 #0 !" 5 '
2 ' ' ' "

/
6 5 #0 '5 #* - # '
# # '' ' - - 5
' "< & $ 5 #0 % 5 #* 9

" !5 #0 # % "
" $ !" ' & "
=" "( ) 5 ## % " & : # "
@" . & # !" - 7"
>" 0 5 #0 # !" ' "

* & $ - # #9 " '"


- $- --!@= @@" #7"

/ $ %
0 !5 #0 # & "( ) # % " # %
$ D # E ' ' "

& ' / ( 0
' ' 5 #0 & & '
"( ) $ " !5 #0 # # $
' ' + & + !" " #
' $ & 7 # & ' & #
# # $ ". # - # # $ & - $ -
!" " ( ' -
$ & 7# 3 =4"

#Region "VB6 Events"

Public Event DateChanged(ByVal StartDate As String, ByVal EndDate As String)

#End Region

#Region "VB6 Properties"

Public WriteOnly Property ShowToday() As Boolean


Set(ByVal value As Boolean)
calendar.ShowToday = value
End Set
End Property

#End Region

#Region "VB6 Methods"

Public Sub SetCalendar(ByVal month As Integer, _


ByVal year As Integer)
calendar.SetDate(New Date(year, month, 1))
End Sub
#End Region

Private Sub calendar_DateChanged _


(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.DateRangeEventArgs) _
Handles calendar.DateChanged
RaiseEvent DateChanged(e.Start.ToShortDateString(), _
e.End.ToShortDateString())
End Sub
, ! - . +"

*+ $ %
6 # !" - 7-
5 #0 "- # ' # % " 5' ' "- # '
& $ 5 #0 " ' "

# - 5 #0 # % " 5' -
& & : # "

5' ## $ - $ $
* 3 " ' ' # % # "* # % -
' ' * # '
. $ ? < # "$- ' "

, - * . - ( $ %
' 5 #0 !" &
"( ) # % !" - 7 3* B4"
: # " $ %

/ / (
. & !" ' "6 & &
"( ) # # $ 3 @4"

Private Sub Form_Load()


With interopUserControl
.ShowToday = True
.SetCalendar 2, 2007
End With
End Sub

Private Sub interopUserControl_DateChanged _


(ByVal StartDate As String, _
ByVal EndDate As String)
Label1 = StartDate
Label2 = EndDate
End Sub
, & - . 58

5' ' "( ) 5 #0 & $


!" $ ' ": & & - "( ) "

) *
• 6 5 #0 !" 5 ' "
• - # - 9
o . & # # $ - ' "
o .$ ' - "
• & "( ) ' ' 5 #0 "
• 6 , $ "( ) " 0 + ,
$ "
• 6 '5 #0 "
• 6 "( ) * 8 & ; , 5' "
• 6 5 #0 !" ' , #
. $ ? # ' 3' 7 # G ' : ''
4"

1 . ' /
- ## & 7 - & "
+ '' ## ' & 9 ## $ $ -
" ' ## & & 7 ' '
' "

' "( ) # % $ '


* 3 " - 3* 4"

8 3 # * 3 " $

' !" # % $ ' '


5 #* + - 3* 4"

=
3 # " < ,$

' & !" 7 # 3 >4 & # '


5 #* + - "5 & & 2 " $ % '
$ & ## # & "0 ' # +
$ # ' ' " 5' !"
## $ $* # #' 8,
$ "

Public g_InteropToolbox As InteropToolbox

Sub Main()
Set g_InteropToolbox = New InteropToolbox
g_InteropToolbox.Initialize
g_InteropToolbox.EventMessenger.RaiseApplicationStartedupEvent

Dim frm1 As New Form1


frm1.Show vbModal

g_InteropToolbox.EventMessenger.RaiseApplicationShutdownEvent
End Sub
, 4 " $ % )

' & !" 7 # 3 !4 & & ##


$ & - "

g_InteropToolbox.EventMessenger.RaiseApplicationEvent _
"Connecting", "NorthwindDB"
g_InteropToolbox.Globals.Add "Username", "JohnD"
, 5 - . 58 # " $ %

' & "( ) 5 #5 ' "$- ' ' !5 #* -


# % 3Private Sub HandleAppEvents(ByVal type As String, ByVal params As Object) _
Handles _mesenger.ApplicationEventRaised
If (type = "Connecting") Then
ConnectDB(params.ToString())

@
End If
End Sub

G4 & & $ & $ - "

Private _toolbox As New InteropToolbox


Private WithEvents _mesenger As InteropEventMessenger = _toolbox.EventMessenger

Private Sub HandleAppEvents(ByVal type As String, ByVal params As Object) _


Handles _mesenger.ApplicationEventRaised
If (type = "Connecting") Then
ConnectDB(params.ToString())
End If
End Sub

, 7 - . +" #

' & 7 #
3My.InteropToolbox.EventMessenger.RaiseApplicationEvent("SEVERE_ERROR", _
"Connection Lost.")

4 & ## $
"

My.InteropToolbox.EventMessenger.RaiseApplicationEvent("SEVERE_ERROR", _
"Connection Lost.")

, 9

' & 7 # 3 B4 & !" A


$ "

Public g_InteropToolbox As InteropToolbox


Private WithEvents g_InteropMessenger As InteropEventMessenger
Private Sub Form_Load()
Set g_InteropToolbox = New InteropToolbox
g_InteropToolbox.Initialize
Set g_InteropMessenger = g_InteropToolbox.EventMessenger
g_InteropToolbox.EventMessenger.RaiseApplicationStartedupEvent
End Sub
Private Sub g_InteropMessenger_ApplicationEventRaised _
(ByVal eventName As String, ByVal eventArgs As Variant)
If eventName = "SEVERE_ERROR" Then
MsgBox eventArgs, vbCritical + vbOKOnly
End If
End Sub
, : = - . 58

1 "
$ & # $ # $ ' -
- " ## - - & - &
- # 2 - ' # A
- "6 & - ' "( )
& - - - +# - 9

" & !" 5 ) "

>
" "( ) - # & * & #
!")?) # # !" # %

> $ 3

=" & $ - +# "( ) - "


@" !" 5 ) & & # % "6 & $
- +# !" " !"
- "6 & - - "

5 # - !" $ & #
"( ) - " ' + $ !"
"

1 #
# - ## &
' - ## " $ ' 9
!" I + # 1 2 "( ) ## % +:
# ; ' 3; ' 4 : ". # + '
$ ' "

* & $ - # #9 " '"


- $- --!@= @>" #7"

2
$ # - ## - "( ) ## % "
## 5 #* "

* # # ' # 9

" # 1 & / ?I 1 & /"


!" # "

!
" "( ) # ' ## "( ) * & + ="> $ I + 3 I 4"
' & + # 8 # "

& #I % "( ) -
5 #* " & $ # - & 7 '
# A 3* 4"

! '

6 + - 5 #* : #
# # # ' ' 1* "

. ' ? - 7' #I % # # # A "


* & 1 & 5 =" "( ) * & + ="> I ' 5 #
* ; - - I + " - 7 - &
+' # A 9 ' 1 - & ' "
* & & & # A ' ' 1 - "

G
& "# # ' ? $ %

# !" " 7 ' !" #


#I % " + !" : # ' : "

' - #I % A + # -
* ) "

* ' - 1 & 5 # # +
#' ' D1 & 5 # E"

$ # - ## 5 #0 "5 ; '
: # "( ) 5 # - # ' !" #
# 1 2 # + "

* # # ' # 9

" # 1 & ?I 1 & "


; ' : "
" # "( ) * & + ="> I " # '
- # - ' "( ) * & + # '
# # + "
; ' : 1 & ?I 1 & - # :
# & $ " ' $ ' 5 #
0 '5 #* - 5 #* & +& ; ' : "

; ' : # & ' ' " !5 #0 # % #


' ' 3<!-- You don't need to worry about anything in this file unless
you're
using registration-free COM.
There should be an appropriate <clrclass> section for every InteropUserControl
defined in the project -->
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">
<assemblyIdentity
type="win32"
name="InteropUserControlDemo"
version="1.0.0.0" />
<clrClass
clsid="{9acd49fc-5e4c-4791-9961-289cc8bafee2}"
progid="InteropUserControlDemo.InteropUserControl"
threadingModel="Both"
name="InteropUserControlDemo.InteropUserControl" >
</clrClass>
</assembly>

4" ' ' ' ' 5 #0 " ' "

<!-- You don't need to worry about anything in this file unless you're
using registration-free COM.
There should be an appropriate <clrclass> section for every InteropUserControl
defined in the project -->
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">
<assemblyIdentity
type="win32"
name="InteropUserControlDemo"
version="1.0.0.0" />
<clrClass
clsid="{9acd49fc-5e4c-4791-9961-289cc8bafee2}"
progid="InteropUserControlDemo.InteropUserControl"
threadingModel="Both"
name="InteropUserControlDemo.InteropUserControl" >
</clrClass>
</assembly>

, 8 $ 3

5' $ ' $ '


- 9 " - # - '
- "

6 ' ' 3<?xml version="1.0" encoding="UTF-8"


standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity type="win32" name="Project1" version="1.0.0.0"
processorArchitecture="x86" />
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="InteropUserControlDemo"
version="1.0.0.0" />
</dependentAssembly>
</dependency>
</assembly>

B
4" # ' ' !" " 7 ' +
' & $ 9 ' ' !" " 7 ' * %
' ' ' - * % 3 "

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>


<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity type="win32" name="Project1" version="1.0.0.0"
processorArchitecture="x86" />
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="InteropUserControlDemo"
version="1.0.0.0" />
</dependentAssembly>
</dependency>
</assembly>

, 3

5 7 #
- $ * ' !" " 7 ' >
' "( ) - 3" 4 ' " $ - $ -
' " 7 ' - "

6 - ' !" I + # 1 2
# 3* 4"

4 - . 58' < > ; )

3
$ # - ## 5 #0 "5 +:
# ## ' "( ) * & +"

* # # ' # 9
" # 1 & ?I 1 & "
; ' : " +: # ## : "
!" # "
" # $ "( ) * & + ="> I " +: &
# A "

+ ## "( ) ## & !"


## # " # % !" " 7 ' '
' ' ; ' : # 3 4 - 3* 4"

5 <1

6 ' # % - # % 8 +% # "
' $ - # " "$-
!" " 7 ' 3 4"

Module Launcher

Sub Main()
Process.Start("Project1.exe")
End Sub

End Module
, - . +" , #

5' ## # ' .## 1 & * .##


& & & # & ## "

6 +: # ' - ' $ # - # % 8# #
"< + & - # ' 3* 4 + +:
& # A & # ' "
7 <1 $ #

* ' - # - ## - +: #
#' ' D +: E"

#
0 5 #* + " 7 # 7 !"
## "( ) " 6 ' ' "( ) * & + - $
## & $ # - $ $
# - "6 + ## # # '
"( ) # ' "* + ## ' # +
# - ## 8 + #"

1 # - 5 #0 ' 5 #* " ##
'' # ' ' 7 # ## !" 5
## ". 5 #0 '' ' 7- - & + -
' $ & ## ' " 5 #0 ## # #
# ' # ## - ; ' : +: "

,
D # .## & 5 #* " + E
#9 - " " $- $ G ! @
# ## & #' + " #7

D5 #* C 3 .# 4E

#9 - " " $- $ = >


#' + $ " #7

D 5 # 0# E
(*
#9 " " '" * 0 $- #

!" ;
#9 " '" - $- ' " #7

D< & 5E J
#9 " '" - $- --@!! !" #7

DK $ # & E
30C - - $ # & 4
#9 - " "

D ## 9.< - !" L > .## E


#9 " '" - = =B3 " 4" #7

D)7 !. $ ? )?) 1 > 5 #* + E


#9 " '" - - --=BG@ B3 " 4" #7

D0# !" .## "( ) >E


3 ' # !" ## & & - '
5 #* + & "4
#9 " '" - - @ >@ " #7

0# # ' . '
#9 & & & " '"

I ' .
#9 & & & "$- " ' " #7

You might also like