Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing a .NET COM Class library (dll) in VB6; Compile error

Status
Not open for further replies.

robz2009

Programmer
Apr 20, 2009
41
GB
I am attempting to use a VB.NET Com Class Library in a VB6; Standard exe application but when attempting to call one of the functions I get the error "Variable uses an Automation type not supported in Visual Basic". The source code for my .dll (VB.NET) is this,

Imports Oracle.DataAccess.Client
Imports System.Configuration

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

#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 = "bce9a99a-4452-4bdb-907b-ad293d77f257"
Public Const InterfaceId As String = "2abdb7ab-6926-4164-acd9-f9774931e336"
Public Const EventsId As String = "f8283f86-3698-4a60-b093-ef330c747702"
#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

Public Structure FlowLogTransResponse
Dim FlowLogID As Long
Dim TransResult As Integer
Dim Message As String
End Structure

Public Structure FlowLogTransRequest
Dim FlowLogID As Long
Dim FlowID As Integer
Dim FlowStatusFlag As Char
Dim FlowFileName As String
Dim FlowLoadDate As Date
End Structure

Public Function CreateFlowLog(ByVal transin As FlowLogTransRequest) As FlowLogTransResponse

Dim response As FlowLogTransResponse

Dim oradb As String = ConfigurationManager.ConnectionStrings("AppName").ConnectionString.ToString

Dim conn As New OracleConnection()
conn.ConnectionString = oradb

Dim cmd As New OracleCommand()
cmd.Connection = conn
cmd.CommandText = "sp_insert_mstifl_data_flow_log"
cmd.CommandType = CommandType.StoredProcedure

cmd.Parameters.Add(New OracleParameter("flowid", OracleDbType.Int32)).Value = transin.FlowID
cmd.Parameters.Add(New OracleParameter("flowstatusflag", OracleDbType.Varchar2)).Value = transin.FlowStatusFlag
cmd.Parameters.Add(New OracleParameter("flowfilename", OracleDbType.Varchar2)).Value = transin.FlowFileName
cmd.Parameters.Add(New OracleParameter("flowloaddate", OracleDbType.Date)).Value = transin.FlowLoadDate

cmd.Parameters.Add(New OracleParameter("flowlogid", OracleDbType.Int32)).Direction = ParameterDirection.Output
cmd.Parameters.Add(New OracleParameter("flowresult", OracleDbType.Int32)).Direction = ParameterDirection.Output
cmd.Parameters.Add(New OracleParameter("flowmessage", OracleDbType.Varchar2, 1000)).Direction = ParameterDirection.Output

conn.Open()

cmd.ExecuteNonQuery()

response.FlowLogID = Convert.ToInt32(cmd.Parameters("flowlogid").Value.ToString())
response.TransResult = Convert.ToInt32(cmd.Parameters("flowresult").Value.ToString())
response.Message = Convert.ToString(cmd.Parameters("flowmessage").Value.ToString())

Return response

conn.Close()

End Function

End Class


The code in my VB6 app is this,

Private Sub Command1_Click()

Dim myObject As FlowLog.FlowLog
Set myObject = New FlowLog.FlowLog

Dim insert As FlowLogTransRequest 'Type for VB **

insert.FlowID = 101
insert.FlowStatusFlag = "F"
insert.FlowFileName = "Testing28Jan.file"
insert.FlowLoadDate = Now()

Dim retval As FlowLogTransResponse 'Type for VB **

retval = myObject.CreateFlowLog(insert)

Dim id As Long
Dim result As Integer
Dim message As String

id = retval.FlowLogID
result = retval.TransResult
message = retval.message

End Sub


The Types have been setup in VB6 to mirror the Structures in VB.NET. The line in bold is what is generating the error.

s the problem with the Structures referenced in VB.NET? Should I not be using Types to mirror the information (Structures) which is passed in and then back out via the Class Library in .NET?

Any advice\suggestions would be most grateful.

 
This article goes into some detail about your error. From what I'm reading in brief, there are some .Net types that have to be messed with before they are compatible with VB6 types. I'm having the feeling you might want to investigate string, given that VB6 string is stack-based and .Net string is heap-based (isn't it?). You may need to work with that.

And one more thing, if I may: if you're going to use red for code, it's much easier to read if you put it in code blocks, thus:
Code:
[COLOR=red]Private Sub Command1_Click()

Dim myObject As FlowLog.FlowLog
Set myObject = New FlowLog.FlowLog

Dim insert As FlowLogTransRequest 'Type for VB **

insert.FlowID = 101
[/color]
The reason for this is that for some reason the eye has great difficulty focusing on both red and blue light at the same time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top