Javascriptを使用して呼び出す必要のあるac#クラスライブラリがあります。以下はC#クラスのコードです。
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms; //required for message box.
namespace csharp.activex.sample
{
[Guid("0D53A3E8-E51A-49C7-944E-E72A2064F938"),
InterfaceType(ComInterfaceType.InterfaceIsDual),
ComVisible(true)]
public interface IHello
{
[DispId(1)]
int ShowDialog();
};
[
Guid("873355E1-2D0D-476f-9BEF-C7E645024C32"),
ProgId("csharpAx.CHello"),
ClassInterface(ClassInterfaceType.None),
ComDefaultInterface(typeof(IHello)),
ComVisible(true)
]
public class CHello : IHello
{
#region [IHello implementation]
public string Hello()
{
return "Hello from CHello object";
}
public int ShowDialog()
{
System.Windows.Forms.MessageBox.Show("C# is awesome");
return 0;
}
#endregion
};
public class Class1
{
public void showDialog() {
MessageBox.Show("Visual c# is awesome!");
}
}
}
クラスをビルドすると、c:\DLLにコピーしたdllファイルが取得されます。以下のコードは、DLLを登録するために使用されます
regasm C:\DLL\ActiveXClass.dll /codebase /tlb
メッセージタイプが正常に登録されました。
次のJavaScriptコードを使用してhtmlファイルを作成します。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script type='text/javascript'>
var myAx1;
function startService(){
myAx1 = new ActiveXObject("csharpAx.CHello");
if(myAx1 != null)
{
myAx1.showDialog();
}
else{
alert("failed");
}
return false;
}
</script>
</head>
<body class="sapUiBody" role="application">
<div id="content"></div>
<a href='#' onclick='return startService()'>StartService</a><br />
</body>
</html>
このようにして得られた結果ページで、サービスの開始をクリックします。しかし、「失敗」や「Visual C#は素晴らしい」などのアラートは表示されません。
助けてください