From 7461751b6efd76b91343a75b75b41ef7491b807c Mon Sep 17 00:00:00 2001 From: Kerong Hu Date: Thu, 1 Sep 2016 10:18:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0param=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实现param读取 --- .gitignore | 174 +++++++++++++++++++++++++++++ ActiveXObject/ActiveXObject.csproj | 2 + ActiveXObject/ObjectX.cs | 151 +++++++++++++++++++++---- TestActiveX/TestPage.html | 39 ++++--- 4 files changed, 325 insertions(+), 41 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5fe65f0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,174 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +app.publish/ +[Bb]in/ +[Oo]bj/ + +# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets +!packages/*/build/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml +*.pubxml + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +#packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +#*.pfx +*.publishsettings +*.bak + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + +# ========================= +# Windows detritus +# ========================= + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac crap +.DS_Store + +# ========================= +# specifics +# ========================= + +App_Data/ +glob:*.user +*.patch +*.hg +build/ +_build/ +/buildazure +/buildtasks +/artifacts +*.sln.cache +log.xml +profiling/ +*.orig +*.itrace.csdef +*.build.csdef +src/TestResults/* \ No newline at end of file diff --git a/ActiveXObject/ActiveXObject.csproj b/ActiveXObject/ActiveXObject.csproj index 74a17dd..37e10b3 100644 --- a/ActiveXObject/ActiveXObject.csproj +++ b/ActiveXObject/ActiveXObject.csproj @@ -20,6 +20,7 @@ DEBUG;TRACE prompt 4 + true pdbonly @@ -28,6 +29,7 @@ TRACE prompt 4 + true diff --git a/ActiveXObject/ObjectX.cs b/ActiveXObject/ObjectX.cs index 903b904..1c4f9cb 100644 --- a/ActiveXObject/ObjectX.cs +++ b/ActiveXObject/ObjectX.cs @@ -8,7 +8,8 @@ /// http://blogs.msdn.com/b/asiatech/archive/2011/12/05/how-to-develop-and-deploy-activex-control-in-c.aspx -/// http://stackoverflow.com/questions/11175145/create-com-activexobject-in-c-use-from-jscript-with-simple-event +/// http://stackoverflow.com/questions/11175145/create-com-activexobject-in-c-use-from-jscript-with-simple-event +/// http://stackoverflow.com/questions/421857/using-activex-propertybags-from-c-sharp /// /// Register with & "$env:windir\Microsoft.NET\Framework\v4.0.30319\regasm" /codebase /// Unregister with & "$env:windir\Microsoft.NET\Framework\v4.0.30319\regasm" /u @@ -33,27 +34,131 @@ public interface IActiveX { [DispId(10)] string CustomProperty { get; set; } - } - - [ProgId("MyObject")] - [ComVisible(true)] - [ClassInterface(ClassInterfaceType.AutoDual)] - [Guid("7A5D58C7-1C27-4DFF-8C8F-F5876FF94C64")] - [ComSourceInterfaces(typeof(IActiveXEvents))] - public class MyObject : IActiveX - { - - public delegate void OnContextChangeHandler(string data); - public event OnContextChangeHandler OnUpdateString; - - [ComVisible(true)] - public string CustomProperty { get; set; } - - - [ComVisible(true)] - public void SayHello(string who) - { - OnUpdateString(who); - } + } + + [ComVisible(true), ComImport, + Guid("37D84F60-42CB-11CE-8135-00AA004BB851"),//Guid("5738E040-B67F-11d0-BD4D-00A0C911CE86"), + InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface IPersistPropertyBag //: IPersist + { + #region IPersist + [PreserveSig] + /*new*/ int GetClassID([Out] out Guid pClassID); + #endregion + + [PreserveSig] + int InitNew(); + + [PreserveSig] + int Load( + [In] IPropertyBag pPropBag, + [In, MarshalAs(UnmanagedType.Interface)] object pErrorLog + ); + + [PreserveSig] + int Save( + IPropertyBag pPropBag, + [In, MarshalAs(UnmanagedType.Bool)] bool fClearDirty, + [In, MarshalAs(UnmanagedType.Bool)] bool fSaveAllProperties + ); + } + + [ComVisible(true), ComImport, + Guid("55272A00-42CB-11CE-8135-00AA004BB851"), + InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface IPropertyBag + { + [PreserveSig] + int Read( + [In, MarshalAs(UnmanagedType.LPWStr)] string pszPropName, + [In, Out, MarshalAs(UnmanagedType.Struct)] ref object pVar, + [In] IntPtr pErrorLog); + + [PreserveSig] + int Write( + [In, MarshalAs(UnmanagedType.LPWStr)] string pszPropName, + [In, MarshalAs(UnmanagedType.Struct)] ref object pVar); + } + + + + [ProgId("MyObject")] + [ComVisible(true)] + [ClassInterface(ClassInterfaceType.AutoDual)] + [Guid("7A5D58C7-1C27-4DFF-8C8F-F5876FF94C64")] + [ComSourceInterfaces(typeof(IActiveXEvents))] + public class MyObject : IActiveX, IPersistPropertyBag, IPropertyBag + { + + public delegate void OnContextChangeHandler(string data); + public event OnContextChangeHandler OnUpdateString; + + [ComVisible(true)] + public string CustomProperty { get; set; } + + + [ComVisible(true)] + public void SayHello(string who) + { + OnUpdateString(who + " :CustomProperty=" + this.CustomProperty); + MessageBox.Show(" public void SayHello(string who):" + who + " :CustomProperty=" + this.CustomProperty); + } + + + + #region IPropertyBag Members + + public int Read(string pszPropName, ref object pVar, IntPtr pErrorLog) + { + pVar = null; + switch (pszPropName) + { + case "CustomProperty": pVar = this.CustomProperty; break; + + } + + return 0; + } + + public int Write(string pszPropName, ref object pVar) + { + switch (pszPropName) + { + case "CustomProperty": this.CustomProperty = (string)pVar; break; + } + + return 0; + } + + #endregion + + #region IPersistPropertyBag Members + + public int GetClassID(out Guid pClassID) + { + throw new NotImplementedException(); + } + + public int InitNew() + { + return 0; + } + + public int Load(IPropertyBag pPropBag, object pErrorLog) + { + object val = null; + + pPropBag.Read("CustomProperty", ref val, IntPtr.Zero); + Write("CustomProperty", ref val); + return 0; + } + + public int Save(IPropertyBag pPropBag, bool fClearDirty, bool fSaveAllProperties) + { + return 0; + } + + #endregion + } } \ No newline at end of file diff --git a/TestActiveX/TestPage.html b/TestActiveX/TestPage.html index ba3a3d4..ff43e07 100644 --- a/TestActiveX/TestPage.html +++ b/TestActiveX/TestPage.html @@ -1,25 +1,28 @@  - - DemoCSharpActiveX webpage - - - + + DemoCSharpActiveX webpage + + + - + + + - + - + - - + + \ No newline at end of file