Click here to Skip to main content
15,887,275 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am stuck with a piece of code. Could you please help me out with the query.

I have a VB6.0 built com component which passes a collection type object to a c# dll. This collection VB6.0 is a collection of strings (paths as string for mail attachments).

VB6.0 call :
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim attachmentPath1 As String
    Dim attachmentPath2 As String
    attachmentPath1 = "C:\SMTPAttachmentsTest\TestAttachment1.txt"
    attachmentPath2 = "C:\SMTPAttachmentsTest\TestAttachment2.txt"
    attachmentColl.Add (attachmentPath1)
    attachmentColl.Add (attachmentPath2)
    
    'Call to c# dll
    MailHelperSMTPObject.SendMailMessageWOAttachment from.Text, recipient.Text,   recipient.Text, subject.Text, message.Text, attachmentColl 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


The c# code is supposed to catch the attachmentColl collection and read all the string paths in that collection.
C# Code :
/////////////////////////////////////////////////////////////////////////////////
public void SendMailMessageWOAttachment(string from, string to, string cc, string subject, string body, object  AttachmentPaths)
        {
            string SMTPSrv;
            Int32 SMTPPort;
            MailMessage mMailMessage = new MailMessage();
            mMailMessage.From = new MailAddress(from);
            mMailMessage.To.Add(new MailAddress(to));
            mMailMessage.CC.Add(new MailAddress(cc));
            mMailMessage.Subject = subject;
            mMailMessage.Body = body;
            SmtpClient mSmtpClient = new SmtpClient(SMTPSrv);
            mSmtpClient.Host = SMTPSrv;
            mSmtpClient.Port = SMTPPort;

            Attachment attach1;

            foreach (object i in AttachmentPaths)
            {
                attach1 = new Attachment(i.ToString());
                mMailMessage.Attachments.Add(attach1);
            }

            mSmtpClient.Send(mMailMessage);
        }
/////////////////////////////////////////////////////////////////////////////////


The problem is that, I cannot change the VB code. I can change only c# code to catch the VB call. I have tried numerous combinations to catch the collection object from VB6.0 but unable to do so. The code works perfect when I remove the attachment collection object from VB6.0 code. But it give a a runtime error of Automation and interface or invalid argument or parameter call. I am using a callable wrapper.

Please help.
Posted
Updated 15-Aug-11 0:08am
v2

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900