VB6.0转C#com互操作问题 [英] VB6.0 to C# com interop problem

查看:74
本文介绍了VB6.0转C#com互操作问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我陷入了一段代码.您能帮我查询一下吗.

我有一个VB6.0内置的com组件,该组件将集合类型对象传递给c#dll. VB6.0集合是字符串的集合(路径为邮件附件的字符串).

VB6.0通话:

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 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''



应该使用C#代码来捕获attachmentColl集合并读取该集合中的所有字符串路径.
C#代码:



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);
        }
/////////////////////////////////////////////////////////////////////////////////



问题是,我无法更改VB代码.我只能更改c#代码来捕获VB调用.我尝试了多种组合以从VB6.0捕获收集对象,但是无法做到这一点.当我从VB6.0代码中删除附件集合对象时,该代码可以完美地工作.但是,它会给出自动化和接口的运行时错误,或者给出无效的参数或参数调用.我正在使用可调用的包装器.

请帮忙.



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.

推荐答案

您是否签出了这篇文章:了解与.NET应用程序的经典COM互操作性 [ ^ ]
Have you checked out this article: Understanding Classic COM Interoperability With .NET Applications[^]


这篇关于VB6.0转C#com互操作问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆