How to show a form


H

hon123456

Dear all,

I have written a com using VB.Net 2005. And I have build it
with com interop selected. What I want is to show a form by VB6
through the function call.

The following is my code in VB.net

<ComClass(ComClass1.ClassId, ComClass1.InterfaceId,
ComClass1.EventsId)> _
Public Class ComClass1

#Region "COM GUID"
' ³o¨Ç GUID ´£¨Ñ¤F³o­ÓÃþ§Oªº COM ÃѧO
' »P¨ä COM ªº¤¶­±¡C¦pªG±zÅܧó³o¨Ç³]©w¡A²{¦³ªº
' ¥Î¤áºÝ±NµLªk¦A¦s¨ú¸ÓÃþ§O¡C
Public Const ClassId As String = "ba44c9f9-
e814-46cc-8449-8b2222d90ca2"
Public Const InterfaceId As String = "6b26373a-7cf4-4cd3-bf77-
fabda12c6119"
Public Const EventsId As String = "2d8bef88-e194-40cc-900f-
cd1377faa6ff"
#End Region

' ¥i«Ø¥ßªº COM Ãþ§O¥²¶·­n¦³¤@­Ó¨S¦³°Ñ¼Æªº Public Sub New()¡A
' §_«h¡A¸ÓÃþ§O±NµLªk©ó COM µn¿ý¤¤¤©¥Hµn¿ý¡A
' ¦Ó¥B¤]µLªk³z¹L
' CreateObject ¨Ó«Ø¥ß¸ÓÃþ§O¡C
Public Sub New()
MyBase.New()
End Sub

Public Function myFunction() As Integer
Dim formshow As New Form1
Return 200
formshow.Show()
End Function

End Class

And then I wrtie the following code in VB6

Private Sub Command1_Click()
Dim myObject As TestProj.ComClass1
Set myObject = New TestProj.ComClass1
MsgBox myObject.myFunction
End Sub

The msgbox can function , it shows "200". But no form was showed in
VB6. What's wrong with my code? Thanks
 
Ad

Advertisements

S

Stephany Young

Return returns immediately, does not pass go and does not collect $200.


Dear all,

I have written a com using VB.Net 2005. And I have build it
with com interop selected. What I want is to show a form by VB6
through the function call.

The following is my code in VB.net

<ComClass(ComClass1.ClassId, ComClass1.InterfaceId,
ComClass1.EventsId)> _
Public Class ComClass1

#Region "COM GUID"
' ³o¨Ç GUID ´£¨Ñ¤F³o­ÓÃþ§Oªº COM ÃѧO
' »P¨ä COM ªº¤¶­±¡C¦pªG±zÅܧó³o¨Ç³]©w¡A²{¦³ªº
' ¥Î¤áºÝ±NµLªk¦A¦s¨ú¸ÓÃþ§O¡C
Public Const ClassId As String = "ba44c9f9-
e814-46cc-8449-8b2222d90ca2"
Public Const InterfaceId As String = "6b26373a-7cf4-4cd3-bf77-
fabda12c6119"
Public Const EventsId As String = "2d8bef88-e194-40cc-900f-
cd1377faa6ff"
#End Region

' ¥i«Ø¥ßªº COM Ãþ§O¥²¶·­n¦³¤@­Ó¨S¦³°Ñ¼Æªº Public Sub New()¡A
' §_«h¡A¸ÓÃþ§O±NµLªk©ó COM µn¿ý¤¤¤©¥Hµn¿ý¡A
' ¦Ó¥B¤]µLªk³z¹L
' CreateObject ¨Ó«Ø¥ß¸ÓÃþ§O¡C
Public Sub New()
MyBase.New()
End Sub

Public Function myFunction() As Integer
Dim formshow As New Form1
Return 200
formshow.Show()
End Function

End Class

And then I wrtie the following code in VB6

Private Sub Command1_Click()
Dim myObject As TestProj.ComClass1
Set myObject = New TestProj.ComClass1
MsgBox myObject.myFunction
End Sub

The msgbox can function , it shows "200". But no form was showed in
VB6. What's wrong with my code? Thanks
 
A

Armin Zingler

Stephany Young said:
Return returns immediately, does not pass go and does not collect
$200.

Hehe...lol...I think I got it. ...only $200?? Were 4000 DM (~2000 Euros
now). Low budget version, right? :)
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top