C # Development COM components

Source: Internet
Author: User
Tags empty interface sendfile

1, define the interface

(1) Add [Guid ("1ea4dbf0-3c3b-11cf-810c-00aa00389b71") above the interface]


(2) Add [DispId (i)] to each method

Using System;
Using System.Runtime.InteropServices;
Namespace Leading.Mis.NewsMonitor
...... {
/**//**//**////<summary>
Definition of the Message monitoring interface
</summary>
[Guid ("1ea4dbf0-3c3b-11cf-810c-00aa00389b71")]
public interface Inewsmonitor
...... {
When sending a file, record the sender, the receiver, and the file name sent when sending the file, record sender, receiver and sent filename #region when sending the file, record sender, receiver and sent filename
/**//**//**////<summary>
When sending a file, record the sender, receiver and the file name sent
</summary>
<param name= "strsendid" > File sender </param>
<param name= "Strtargetid" > File recipient </param>
<param name= "strFileName" > FileName </param>
[DispId (1)]
void SendFile (String strsendid,string strtargetid,string strFileName);
#endregion

When receiving files, the record file recipient, sender and sent file name when receiving file, record file receiver, sender and send filename #region when receiving file, record file receiver, sender and send filename
/**//**//**////<summary>
Document recipient, sender, and sent file name when accepting files
</summary>
<param name= "Strreceiveid" > File recipient </param>
<param name= "strsendid" > File sender </param>
<param name= "strFileName" > FileName </param>
[DispId (2)]
void Recvfile (String strreceiveid,string strsendid,string strFileName);
#endregion

After the file is sent successfully, the record sender, receiver and sent file name file are sent successfully after the record sender, receiver and send the filename #region file sent successfully, record sender, receiver and send filename
/**//**//**////<summary>
After the file is sent, record the sender, the receiver, and the file name sent
</summary>
<param name= "strsendid" > File sender </param>
<param name= "Strtargetid" > File recipient </param>
<param name= "strFileName" > FileName </param>
[DispId (3)]
void Filesendok (String strsendid,string strtargetid,string strFileName);
#endregion

Cancel file when sending, record sender, receiver and send filename cancel file send, record sender, receiver and send filename #region cancel file send, record sender, receiver and send filename
/**//**//**////<summary>
When a file is sent, record the sender, the receiver, and the file name sent
</summary>
<param name= "Strcancelid" > Cancel file Sender </param>
<param name= "Strtargetid" > file sent to each other </param>
<param name= "strFileName" > FileName </param>
[DispId (4)]
void Filesendcancel (String strcancelid,string strtargetid,string strFileName);
#endregion

}//End Interface Inewsmonitor

}//end namespace Leading.Mis.NewsMonitor

2, the implementation of the class

(1) Add a [Guid ("1ea4dbf0-3c3b-11cf-810c-00aa00389b71")] above the class
[ClassInterface (ClassInterfaceType.None)]

Using System;
Using System.IO;
Using System.Runtime.InteropServices;

Namespace Leading.Mis.NewsMonitor
...... {
/**//**//**////<summary>
Implementation of message monitoring class
</summary>
[Guid ("1ea4dbf0-3c3b-11cf-810c-00aa00389b71")]
[ClassInterface (ClassInterfaceType.None)]
public class Newsmonitor:inewsmonitor
...... {
Private Field #region Private field

private string FilePath = String. Empty;
private string writeLine = String. Empty;

#endregion

Private Method #region Private method

private void Newsmsg ()
...... {
StreamWriter sw = null;
if (file.exists (FilePath))
...... {
SW = File.appendtext (FilePath);
}
Else
...... {
FileStream fs = File.create (FilePath);
SW = new StreamWriter (FS);
}
Sw. WriteLine (WriteLine);
Sw. Close ();
}

#endregion

Common method #region Common method

When sending a file, record the sender, the receiver, and the file name sent #region send the file, record the sender, receiver, and send the filename
/**////<summary>
When sending a file, record the sender, receiver and the file name sent
</summary>
<param name= "strsendid" > File sender </param>
<param name= "Strtargetid" > File recipient </param>
<param name= "strFileName" > FileName </param>
public void SendFile (string strsendid,string strtargetid,string strFileName)
...... {
FilePath = @ "C:msgmonitorsendfile.txt";
WriteLine = Strsendid + "to" + Strtargetid + "Send <" + strFileName + "> file";
Newsmsg ();
}
#endregion

When a file is received, the record file recipient, the sender, and the file name sent #region receive the file, the record file recipient, the sender, and the file name sent
/**////<summary>
Document recipient, sender, and sent file name when accepting files
</summary>
<param name= "Strreceiveid" > File recipient </param>
<param name= "strsendid" > File sender </param>
<param name= "strFileName" > FileName </param>
public void Recvfile (string strreceiveid,string strsendid,string strFileName)
...... {
FilePath = @ "C:msgmonitorrecvfile.txt";
WriteLine = Strreceiveid + "received" + Strsendid + "sent <" + strFileName + "> file";
Newsmsg ();
}
#endregion

After the file is sent successfully, the record sender, receiver and sent file name #region files are sent successfully after the record sender, receiver and sent file name
/**////<summary>
After the file is sent, record the sender, the receiver, and the file name sent
</summary>
<param name= "strsendid" > File sender </param>
<param name= "Strtargetid" > File recipient </param>
<param name= "strFileName" > FileName </param>
public void Filesendok (string strsendid,string strtargetid,string strFileName)
...... {
FilePath = @ "C:msgmonitorfilesendok.txt";
WriteLine = Strsendid + "has succeeded to" + Strtargetid + "Send <" + strFileName + "> file";
Newsmsg ();
}
#endregion

When file is sent, record sender, receiver and sent filename #region Cancel file send, record sender, receiver and send filename
/**////<summary>
When a file is sent, record the sender, the receiver, and the file name sent
</summary>
<param name= "Strcancelid" > Cancel file Sender </param>
<param name= "Strtargetid" > file sent to each other </param>
<param name= "strFileName" > FileName </param>
public void Filesendcancel (string strcancelid,string strtargetid,string strFileName)
...... {
FilePath = @ "C:msgmonitorfilesendcancel.txt";
WriteLine = Strcancelid + "Cancel and" + Strtargetid + "Send <" + strFileName + "> file";
Newsmsg ();
}
#endregion

#endregion
}//End Class Newsmonitor

}//end namespace Leading.Mis.NewsMonitor

3, register with the Regasm tool

Regasm newsmsg.dll/tlb:newsmsg.tlb



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.