Hi:
我用c#vs2017創建了一個activex 64位dll工程(非any cpu),編譯通過,在IE瀏覽器html網頁上運行正常,但是在IE 瀏覽器F12除錯html代碼時提示沒有加載activex。作業系統是Win10 64位,IE11.謝謝各位。
代碼如下:
.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace ClassLibrary1
{
[ProgId("DemoClassLibrary1.HelloWorld")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[Guid("731632A9-05F4-4B8E-A34E-BCA8168843B9")]
[ComVisible(true)]
public class Class1
{
[ComVisible(true)]
public String SayHello()
{
return "helloworld";
}
}
}
.csproj
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="/////////////////////">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{0D958562-8481-4A7F-8482-09EAED3B86C0}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ClassLibrary1</RootNamespace>
<AssemblyName>ClassLibrary1</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<RegisterForComInterop>true</RegisterForComInterop>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<Prefer32Bit>false</Prefer32Bit>
<PlatformTarget>x64</PlatformTarget>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>false</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>miyao.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="miyao.pfx" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
.html
<!DOCTYPE>
<html>
<head>
<title>DemoCSharpActiveX webpage</title>
</head>
<body>
<button>1231123</button>
<OBJECT id="DemoActiveX" classid="clsid:731632A9-05F4-4B8E-A34E-BCA8168843B9"></OBJECT>
<script type="text/javascript">
try {
var obj = document.DemoActiveX
if (obj) {
alert(obj.SayHello());
} else {
alert("Object is not created!");
}
} catch (ex) {
alert("Some error happens, error message is: " + ex.Description);
}
</script>
</body>
</html>
注冊dll:
c:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe /register /codebase "C:\Users\Dell\Desktop\ClassLibrary1\ClassLibrary1\bin\Debug\ClassLibrary1.dll"
注冊表:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main]
"TabProcGrowth"=dword:00000000
#########################################
運行結果,分兩種情況:
1.直接運行,正常:
*.使用IE打開html網頁,正常。
2.使用IE F12除錯html,例外:
*.打開IE
*.按F12
*.輸入本地html檔案地址
*.提示"Object doesn't support property or method 'SayHello'",html的object控制元件(activex控制元件)沒有加載成功。
問題:
為什么沒有加載成功,我需要使用IE F12除錯html代碼。
截圖:
配置:










結論:
正常:

例外:

uj5u.com熱心網友回復:
你瀏覽器 沒啟用 activexuj5u.com熱心網友回復:
IE加載html可以正常運行,一旦使用F12除錯就例外。
我參考這個網頁做的https://blogs.msdn.microsoft.com/asiatech/2011/12/05/how-to-develop-and-deploy-activex-control-in-c/
uj5u.com熱心網友回復:
相關代碼可以在這里下載沒有積分,https://download.csdn.net/download/crazyeveryday/12068177轉載請註明出處,本文鏈接:https://www.uj5u.com/net/81427.html
標籤:C#
上一篇:mvc分頁
下一篇:WPF求助
