Advertisement

07.15.2008 at 03:05PM PDT, ID: 23567816
[x]
Attachment Details

Calling managed code from VB6

Asked by Bannerman in Microsoft Visual Basic.Net

Tags: ,

I'm trying to call the .NET code from VB6. When I run it, it stops on "a = New sscemail.smtp" with the Run-time error '430': Class does not support AUtomation or does not support expected interface. I have enabled "Register for COM Interop" in the properties of my .NET project. I have added a reference to that project in my VB6 application.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
.NET code:
 
Imports System
Imports System.Net.Mail
Imports System.Runtime.InteropServices
Namespace sscemail
    <Guid("893F6A58-52B1-11DD-8B0C-046D56D89593"), _
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _
    Public Interface _smtp
        <DispId(1)> Function sendmail(ByVal fromAddress As String, ByVal displayName As String, ByVal toAddress As String, ByVal subject As String, ByVal body As String, ByVal html As Boolean, ByVal username As String, ByVal password As String, ByVal host As String, ByVal port As Integer, ByVal enablessl As Boolean) As Boolean
    End Interface
    <Guid("3ce1d9b0-52b7-11dd-ae16-0800200c9a66"), _
         ClassInterface(ClassInterfaceType.None), _
        ProgId("sscemail.smtp")> Public Class smtp
        Implements _smtp
        Public smtp()
        Public Function sendmail(ByVal fromAddress As String, ByVal displayName As String, ByVal toAddress As String, ByVal subject As String, ByVal body As String, ByVal html As Boolean, ByVal username As String, ByVal password As String, ByVal host As String, ByVal port As Integer, ByVal enablessl As Boolean) As Boolean Implements _smtp.sendmail
            Dim msg As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
            msg.To.Add(toAddress)
            msg.From = New MailAddress(fromAddress, displayName, System.Text.Encoding.UTF8)
            msg.Subject = subject
            msg.SubjectEncoding = System.Text.Encoding.UTF8
            msg.Body = body
            msg.BodyEncoding = System.Text.Encoding.UTF8
            msg.IsBodyHtml = html
            msg.Priority = MailPriority.Normal
            'Add the Credentials
            Dim client As SmtpClient = New SmtpClient()
            client.Credentials = New System.Net.NetworkCredential(username, password)
            client.Port = port 'or use 465
            client.Host = host
            client.EnableSsl = enablessl
            Try
                client.Send(msg)
            Catch ex As Exception
                Return False
            End Try
            Return True
        End Function
    End Class
End Namespace
 
 
VB6 code:
Option Explicit
Private Sub cmdSend_Click()
            Dim a As sscemail.smtp
            a = New sscemail.smtp
            MsgBox (a.sendmail("jon@xxx.com", "Jon Califf", "curdie@xxx.com", "Hello this is a test.", "Only testing.", False, "jon@xxx.com", "password", "smtp.gmail.com", 587, True))
            
End Sub
[+][-]07.16.2008 at 05:58AM PDT, ID: 22015402

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.16.2008 at 07:21AM PDT, ID: 22016169

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 02:25AM PDT, ID: 22041920

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Visual Basic.Net
Tags: VB.NET and VB6, COM Interop
Sign Up Now!
Solution Provided By: TheLearnedOne
Participating Experts: 1
Solution Grade: B
 
 
[+][-]08.15.2008 at 04:17AM PDT, ID: 22237180

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628