In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to develop interface forms with COM components of C#". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to develop interface forms with COM components of C#.
C # COM component development 1, define 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. {/ * * / definition of the message monitoring interface / [Guid ("1EA4DBF0-3C3B-11CF-810C-00AA00389B71")] public interface INewsMonitor. {when sending a file, record the sender, receiver, and file name sent, record the sender Receiver and sent file name # region record the sender, receiver, and sent file name / * * / record the sender when sending the file Recipient and sent file name / file sender / / file recipient / / file name [DispId (1)] void SendFile (string strSendID,string strTargetID,string strFileName) # when endregion receives a file, record the receiver, sender and sent file name when receiving the file, record the receiver, sender and sent file name # region when receiving the file, record the receiver, sender and sent file name / * * / when receiving the file Record the file receiver, sender and sent file name / file sender / / file name [DispId (2)] void RecvFile (string strReceiveID,string strSendID,string strFileName) # record the sender, receiver and the sent file name after the endregion file is sent successfully, record the sender, receiver and the sent file name after the region file is sent successfully, record the sender, receiver and the sent file name / * / after the file is sent successfully Record the sender, receiver, and file name sent / file receiver / / file name [DispId (3)] void FileSendOK (string strSendID,string strTargetID,string strFileName) # endregion record sender, receiver and sent file name when canceling file delivery, record sender, receiver and sent file name # region when canceling file delivery, record sender, receiver and sent file name / * * / cancel file delivery Record the sender, receiver and file name sent / / cancel file sender / / file sender / file name [DispId (4)] void FileSendCancel (string strCancelID,string strTargetID,string strFileName) # endregion} / / end interface INewsMonitor} / / end namespace Leading.Mis.NewsMonitor
C # COM component development 2, class implementation
(1) add [Guid ("1EA4DBF0-3C3B-11CF-810C-00AA00389B71")] to the top of the class
[ClassInterface (ClassInterfaceType.None)]
Using System; using System.IO; using System.Runtime.InteropServices Namespace Leading.Mis.NewsMonitor. {/ * * / implementation of message monitoring class / [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 sender, receiver and sent file name # region record sender, receiver and sent file name / * * / when sending a file, record the sender Recipient and sent file name / file sender / / file recipient / file name public void SendFile (string strSendID,string strTargetID,string strFileName). {filePath = @ "c:MsgMonitorSendFile.txt" WriteLine = strSendID + "send to" + strTargetID + "
< " + strFileName + " >File "; NewsMsg () } # when endregion receives a file, record the receiver, sender, and sent file name # region record the receiver, sender, and sent file name / * * / when receiving the file, record the recipient of the file Sender and sent file name / file receiver / / file sender / file name public void RecvFile (string strReceiveID,string strSendID,string strFileName). {filePath = @ "c:MsgMonitorRecvFile.txt" WriteLine = strReceiveID + "received the" + strSendID + "sent
< " + strFileName + " >File "; NewsMsg () } # record the sender, receiver and file name sent after the endregion file is sent successfully # record the sender, receiver and the file name sent / * * / after the region file is sent successfully, record the sender Recipient and sent file name / file sender / / file receiver / file name public void FileSendOK (string strSendID,string strTargetID,string strFileName). {filePath = @ "c:MsgMonitorFileSendOK.txt" WriteLine = strSendID + "successfully sent to" + strTargetID + "
< " + strFileName + " >File "; NewsMsg () } # endregion record sender, receiver and sender file name when canceling file delivery # region record sender, receiver and sent file name / * * / record sender when canceling file delivery Recipient and sent file name / cancel file sender / file sender / file name 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
C # COM component development 3, register with Regasm tool
Regasm NewsMsg.dll / tlb: NewsMsg.tlb
Thank you for your reading, the above is the content of "how to develop interface forms with COM components of C#". After the study of this article, I believe you have a deeper understanding of how to develop interface forms with COM components of C#. The specific use of this component also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.