0
新しいモジュールを実装するように頼まれたプログラムがあります。新しいモジュールにはADKが用意されているので、簡単に行うことができます。ただし、デモコードはC#で書かれています(WPFで動作します)。パラメータなしのイベントハンドラ/登録サービス?
私の質問は、イベントハンドラについてです。私は何の問題もなく、デモのコードを実行することができますVS 2015を使用して
// register dispatch handler
ServiceBase servicebase = _oModule.GetService(ServiceType.DSPBASE);
if (servicebase != null)
{
// handle data received from the dispatch base component
servicebase.Register(EventHandler_DSPBASE);
servicebase.SetDispatchBaseOption(12500, DispatchBase.ROUTE_DATA_RECEIVED);
}
:EventHandlerのがこれで設定されている初期化で
// handle dispatch base events
void EventHandler_DSPBASE(EventBase e)
{
try
{
ServiceEvent serviceEvent = e as ServiceEvent;
if (serviceEvent == null)
return;
// more code here
}
catch (Exception exception)
{
// catch exceptions here
}
}
:C#コードでは、これは、イベントハンドラです。これをVB.NETに変換すると、Event Handlerがパラメータ(EventBase e)を必要とするため、エラーが発生します。初期化セクションでは、このVB.NETコードは実行されません。
Dim servicebase As ServiceBase = _oModule.GetService(ServiceType.DSPBASE)
If servicebase IsNot Nothing Then
' handle data received from the dispatch base component
servicebase.Register(EventHandler_DSPBASE) ' <- error here - red squiggly line in parenthesis
servicebase.SetDispatchBaseOption(12500, DispatchBase.ROUTE_DATA_RECEIVED)
End If
このコードはVB.NETではなくC#で実行される理由はありますか?プロシージャがVB.NETで必要とする引数を渡さずにハンドラを設定できる方法はありますか?
エラーは、実際に何と言っていますか?次のように[AddressOf](https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/addressof-operator)を試してみてください: 'servicebase.Register(AddressOf EventHandler_DSPBASE)'。 –
"Private Sub EventHandler_DSPBASE(EventBase e)"のパラメータ 'e'の引数が指定されていません。 –
誤ってEnterキーを押します。 .Reegister(AddressOf(EventHandler_DSPBASE()))でも赤い線が残っています –