DVader Posted August 21, 2006 Posted August 21, 2006 I've written a DLL in VB.NET and I am trying to use it in a VB6 application. When I run the application from either directly in VB6 or from the executable I get the following error message: "Class does not support automation or does not support expected interface." Here's a snapshot of the DLL code: Option Explicit On Imports System Imports Microsoft.Win32 Imports Microsoft.VisualBasic Imports System.IO Imports System.Security.Permissions Imports System.Text Imports CrystalDecisions.Enterprise Imports CrystalDecisions.Enterprise.Viewing Imports CrystalDecisions.Enterprise.Desktop.Report Imports CrystalDecisions.ReportAppServer.Controllers Imports CrystalDecisions.ReportAppServer.ClientDoc Imports CrystalDecisions.ReportAppServer.DataDefModel Imports CrystalDecisions.CrystalReports.TemplateEngine Imports CrystalDecisions.ReportAppServer.ReportDefModel Imports CrystalDecisions.ReportAppServer.CommonObjectModel Imports CrystalDecisions.ReportAppServer.ObjectFactory Imports System.Windows.Forms Imports System.Runtime.InteropServices Public Enum ReportServer As Integer Development = 0 Test = 1 Production = 2 End Enum Public Enum DocumentType As Integer PDF = 0 MSWord = 1 MSExcel = 2 End Enum <GuidAttribute("A366D469-A20A-4224-ACBA-6BDFE219E34A")> _ Public Interface _IBusinessObjectsServer Function RetrieveRepositoryReport(ByVal pReportName As String, _ ByVal Server As ReportServer, _ ByRef pParamList(,) As String, _ ByVal DBUserName As String, _ ByVal DBPassword As String, _ Optional ByVal SQLServer As String = "", _ Optional ByVal Database As String = "") As ReportClientDocument Sub ViewRepositoryReport(ByVal pReportName As String, _ ByVal Server As ReportServer, _ ByRef pParamList(,) As String, _ ByVal DBUserName As String, _ ByVal DBPassword As String, _ Optional ByVal SQLServer As String = "", _ Optional ByVal Database As String = "") Function ExportRepositoryReport(ByVal pReportName As String, _ ByVal Server As ReportServer, _ ByRef pParamList(,) As String, _ ByVal DBUserName As String, _ ByVal DBPassword As String, _ ByVal pPathAndFilename As String, _ ByVal pDocumentType As DocumentType, _ Optional ByVal SQLServer As String = "", _ Optional ByVal Database As String = "") As Boolean End Interface <System.Runtime.InteropServices.ProgId("BusinessObjectsReportServer"), _ ClassInterface(ClassInterfaceType.None), _ GuidAttribute("E1A6A3DF-6843-4899-BB35-5FB782F90056")> _ Public Class BOEReportServer Implements _IBusinessObjectsServer Friend bolShowExportButton As Boolean = False Friend bolShowGroupTreeButton As Boolean = False Friend bolDisplayGroupTree As Boolean = False Friend bolEnableDrillDown As Boolean = False Friend bolShowRefreshButton As Boolean = False Property ShowGroupTreeButton() As Boolean Get Return bolShowGroupTreeButton End Get Set(ByVal Value As Boolean) bolShowGroupTreeButton = Value End Set End Property Property ShowExportButton() As Boolean Get Return bolShowExportButton End Get Set(ByVal Value As Boolean) bolShowExportButton = Value End Set End Property Property DisplayGroupTree() As Boolean Get Return bolDisplayGroupTree End Get Set(ByVal Value As Boolean) bolDisplayGroupTree = Value End Set End Property Property EnableDrillDown() As Boolean Get Return bolEnableDrillDown End Get Set(ByVal Value As Boolean) bolEnableDrillDown = Value End Set End Property Property ShowRefreshButton() As Boolean Get Return bolShowRefreshButton End Get Set(ByVal Value As Boolean) bolShowRefreshButton = Value End Set End Property Public Function RetrieveRepositoryReport(ByVal pReportName As String, _ ByVal Server As ReportServer, _ ByRef pParamList(,) As String, _ ByVal DBUserName As String, _ ByVal DBPassword As String, _ Optional ByVal SQLServer As String = "", _ Optional ByVal Database As String = "") As ReportClientDocument Implements _IBusinessObjectsServer.RetrieveRepositoryReport CODE REMOVED... End Function Public Sub ViewRepositoryReport(ByVal pReportName As String, _ ByVal Server As ReportServer, _ ByRef pParamList(,) As String, _ ByVal DBUserName As String, _ ByVal DBPassword As String, _ Optional ByVal SQLServer As String = "", _ Optional ByVal Database As String = "") Implements _IBusinessObjectsServer.ViewRepositoryReport CODE REMOVED... End Sub Public Function ExportRepositoryReport(ByVal pReportName As String, _ ByVal Server As ReportServer, _ ByRef pParamList(,) As String, _ ByVal DBUserName As String, _ ByVal DBPassword As String, _ ByVal pPathAndFilename As String, _ ByVal pDocumentType As DocumentType, _ Optional ByVal SQLServer As String = "", _ Optional ByVal Database As String = "") As Boolean Implements _IBusinessObjectsServer.ExportRepositoryReport CODE REMOVED... End Function End Class I've checked the "Register for COM Interop" property of the DLL and added the AssemblyKeyFile line to the AssemblyInfo.vb In the VB6 application I've added the DLL to the references. Here's a sample of the VB6 code: Private Sub cmdReturnReport_Click() On Error GoTo Err_cmdReturnReport_Click Dim strParamList(5, 1) As String Dim strReportName As String strReportName = "EventsByPosition" strParamList(0, 0) = "Area" strParamList(0, 1) = "No" strParamList(1, 0) = "Region" strParamList(1, 1) = "No" strParamList(2, 0) = "From-Date" strParamList(2, 1) = "1995-01-01" strParamList(3, 0) = "To-Date" strParamList(3, 1) = "2004-12-31" strParamList(4, 0) = "Event-Type" strParamList(4, 1) = "J;V" strParamList(5, 0) = "@Position" strParamList(5, 1) = "EQUIPMENT MECHAN" '-------------------------------------------------------- '- Display the report . . . '-------------------------------------------------------- Dim oRS As BusinessObjectsReportServer.BOEReportServer [b]Set oRS = New BusinessObjectsReportServer.BOEReportServer[/b] Call oRS.ViewRepositoryReport(strReportName, ReportServer_Development, strParamList, "HS50_Admin", "HS50_Admin") Exit_cmdReturnReport_Click: Exit Sub Err_cmdReturnReport_Click: MsgBox Err.Description & " - " & Err.Number End Sub The bold line above is the one giving the error. When I type in the lines that reference the DLL the intellisense works. So what am I doing wrong? Quote
Leaders snarfblam Posted August 21, 2006 Leaders Posted August 21, 2006 I believe that you need to mark classes that will be used in VB6 with the ComClass attribute (and it might be a good idea to use some ComVisible attributes too). You also need to make your assembly visible to COM (apply the ComVisible attribute to the assembly in AssemblyInfo.vb or (in VB8) go to the project settings and under the "Application" tab click "Assembly Information" where you can check "Make assembly COM-visible"). Quote [sIGPIC]e[/sIGPIC]
DVader Posted August 21, 2006 Author Posted August 21, 2006 One thing I should have mentioned in my first post was that this DLL needs to be used from either VB6 or .NET, so will any of those changes impact the DLL's use in a .NET application? Quote
Leaders snarfblam Posted August 21, 2006 Leaders Posted August 21, 2006 No. The attributes specify that extra accomodations be made available for COM interop (thunking and marshalling), but this does not affect the behavior within a completely managed environment. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts