Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / April 2006

Tip: Looking for answers? Try searching our database.

ActiveX dll / com in vb.net 2005

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Philip Wagenaar - 23 Apr 2006 15:50 GMT
I created a few plugins in vb6 (activex dll) for an OCR application. Now I am
trying to re-write one simple plugin in vb.net 2005.

In vb6 I created a new ActiveX DLL, added a reference to a dll from the OCR
application, added some, and entered some config info into the ini file of
the OCR application. The code in vb6 is:
Option Explicit

'Ini file
Private m_IniFile As String
Private m_IniSection As String

Private m_SourceImagePath As String
Private m_DebugLogfile As String

'Eyes & Hands Forms objects
Private objTransfer As EHF.TransferApp

Public Function Connect(ByRef ehApp As Object, ByRef strInifile As String,
ByRef strIniSection As String) As Long

   'Setup global App object
   Set objTransfer = ehApp

   'Subscribe to events
   Call objTransfer.Subscribe(Me, "InvoiceTransfer", "OnInvoiceTransfer")
   
   'Remember ini settings
   m_IniFile = strInifile
   m_IniSection = strIniSection
   m_DebugLogfile = GetSetting(m_IniSection, "DebugLogfile", m_IniFile)
   
   Connect = EV_OK
End Function

Public Function Disconnect(ehApp As Object) As Long

   'Release object
   Set objTransfer = Nothing
   
   Disconnect = EV_OK
End Function

Public Function OnInvoiceTransfer() As Long

   MsgBox "KLAAAR: " & objTransfer.Info
   
   
End Function

Now I am trying to create in vb.net 2005. I created a new project as a class
library, added a reference to the OCR application DLL (from the COM tab in
the add reference dialog) and added a new com class and added the following
code:
Imports System.Runtime.InteropServices

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

#Region "COM GUIDs"
   ' These  GUIDs provide the COM identity for this class
   ' and its COM interfaces. If you change them, existing
   ' clients will no longer be able to access the class.
   Public Const ClassId As String = "0541f21e-ea70-47a5-af14-26ae14567c04"
   Public Const InterfaceId As String =
"d33b492b-71ef-45fb-8d83-c84d24a9be37"
   Public Const EventsId As String = "d6bf8cbd-57ac-415e-88ef-6137d1d97ce4"
#End Region

   ' A creatable COM class must have a Public Sub New()
   ' with no parameters, otherwise, the class will not be
   ' registered in the COM registry and cannot be created
   ' via CreateObject.
   Public Sub New()
       MyBase.New()
   End Sub

   'Ini file
   Private m_IniFile As String
   Private m_IniSection As String

   Private m_SourceImagePath As String
   Private m_DebugLogfile As String

   'Eyes & Hands Forms objects
   Private objTransfer As EHF.TransferApp

   Public Function Connect(ByRef ehApp As Object, ByRef strInifile As
String, ByRef strIniSection As String) As Long
       EventLog.WriteEntry("Connect", "Connected")
       'Setup global App object
       objTransfer = ehApp

       'Subscribe to events
       Call objTransfer.Subscribe(Me, "InvoiceTransfer", "OnInvoiceTransfer")

       'Remember ini settings
       m_IniFile = strInifile
       m_IniSection = strIniSection
       m_DebugLogfile = GetSetting(m_IniSection, "DebugLogfile", m_IniFile)

       Connect = EV_OK
   End Function

   Public Function Disconnect(ByVal ehApp As Object) As Long

       'Release object
       objTransfer = Nothing

       Disconnect = EV_OK
   End Function

   Public Function OnInvoiceTransfer() As Long

       MsgBox("KLAAAR: " & objTransfer.Info)

   End Function

End Class

I compile this. I get two DLL's. One from my code and one interop from the
reference I added. I copy both to the machine running the OCR and register
them both using regasm.exe.

But the OCR application does not see the plugin. When I use filemon.exe I
can see that it is loaded, but the OCR application gives and error that it
cannot load the plugin.

Any help?
"Peter Huang" [MSFT] - 24 Apr 2006 06:54 GMT
Hi Philip,

I think you may try to use the vb6 to vb.net upgrade wizard by opening the
vbp file in vs.net ide.
Also did you need to implement special interface or do some special
registry operation?
Based on my knowledge, for Office Addin, we need to regasm the .NET DLL as
a COM Object, but also register it in the Office registry key so that the
office application will be aware of that.

Also I think you may try to contact the OCR application vendor to see what
may cause the addin failed loading.

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Philip Wagenaar - 24 Apr 2006 07:36 GMT
Peter thank you for your reply.

In the vb6 code I do not have to construct a special interface, but I do not
know if vb6 constructs a interface by default that is diffrent from a default
one in .Net.

In vb6 I had to reference a DLL. I also did this in vb.net. An interop dll
is created for this. I also regsitered this dll with regasm.exe. Should this
be enough in theory?

> Hi Philip,
>
[quoted text clipped - 19 lines]
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
"Peter Huang" [MSFT] - 25 Apr 2006 06:22 GMT
Hi Philip,

Commonly for a plugin, similar with a Addin, we need to implement certian
interface, so that the host application will interactive with the plugin
via the interface.
Anyway, if we want to a make common COM DLL in VB.NET.
And to make a common COM DLL in VB.NET, you are correct, we just need to
call regasm after build the VB.NET classlibrary.

For your scenario, I think we may try to isolate the problem via the steps
below.
1. Build a simple VB.NET class library and regam it, call it from VB6 did
it work?
2. In the VB.NET class library , add reference to the another DLL and call
it from VB6 and regasm it, did it work?

Please perform the test and let me know the result.

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Philip Wagenaar - 25 Apr 2006 07:50 GMT
I used the upgrade wizard for vb6 to vb.net and it added the following code
to the class definition

<System.Runtime.InteropServices.ProgId("Transfer_NET.Transfer")> Public
Class Transfer

The OCR application that uses the plugins needs to know the
Transfer_NET.Transfer part to find the class. Then the class needs to
implement a a few functions. And now it works.

In this, or another thread about this issue you told me to look at the
upgrade wizard, and that did the trick! So many thanks for that!

Maybe one last question. If I put msgbox("hello") in the plugin (vb.net of
course) and it is run by the OCR application it shows a message box with the
text hello. Is this a .NET windows forms message box? Or vb6 message box?

> Hi Philip,
>
[quoted text clipped - 24 lines]
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
"Peter Huang" [MSFT] - 26 Apr 2006 03:59 GMT
Hi

The VB.NET msgbox call have some difference with the Winform MessageBox
call.
VB.NET have his own wrap.
But they will call the MessageBox API finally, so I think they did not make
difference.

If you still have any concern, please feel free to post here.

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.