Class1.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:1k
源码类别:

C#编程

开发平台:

Others

  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace Wrox.ProCSharp.COMInterop.Server
  4. {
  5. [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
  6. public interface IMathEvents
  7. {
  8. [DispId(46200)] void CalculationCompleted();
  9. }
  10. [InterfaceType(ComInterfaceType.InterfaceIsDual)]
  11. public interface IWelcome
  12. {
  13. [DispId(60040)] string Greeting(string name);
  14. }
  15. [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  16. public interface IMath
  17. {
  18. int Add(int val1, int val2);
  19. int Sub(int val1, int val2);
  20. }
  21. [ComVisible(false)]
  22. public delegate void CalculationCompletedDelegate();
  23. [ClassInterface(ClassInterfaceType.None)]
  24. [ProgId("Wrox.DotnetComponent")]
  25. [Guid("77839717-40DD-4876-8297-35B98A8402C7")]
  26. [ComSourceInterfaces(typeof(IMathEvents))]
  27. public class DotnetComponent : IWelcome, IMath
  28. {
  29. public DotnetComponent()
  30. {
  31. }
  32. public event CalculationCompletedDelegate CalculationCompleted;
  33. #region IWelcome Members
  34. public string Greeting(string name)
  35. {
  36. return "Hello " + name;
  37. }
  38. #endregion
  39. #region IMath Members
  40. public int Add(int val1, int val2)
  41. {
  42. int result = val1 + val2;
  43. if (CalculationCompleted != null)
  44. CalculationCompleted();
  45. return result;
  46. }
  47. public int Sub(int val1, int val2)
  48. {
  49. int result = val1 - val2;
  50. if (CalculationCompleted != null)
  51. CalculationCompleted();
  52. return result;
  53. }
  54. #endregion
  55. }
  56. }