関数を持つC++ dllプロジェクト(MsgHook.cpp)を持つソリューションがあります:-
BOOL f_closeSEB()
{
logg(fp, "\n\n");
//TerminateProcess(hPiProcess->hProcess,0);
SendMessage(hWndCaller,WM_DESTROY,NULL,NULL);
logg(fp, " SEB exit sequence, destroy window\n");
//logg(fp, "Leave LLKeyboardHook() and return -1\n\n");
return -1;
}
次の方法で、C# Web サービス プロジェクトからこの関数を呼び出そうとしています。
using System.Runtime.InteropServices;
namespace closeSEB
{
partial class closeSEBService
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
public enum commands
{
CloseIt=255
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
[DllImport("MsgHook.dll", SetLastError = true)]
public static extern void runRTS(string serviceName);
protected override void OnCustomCommand(int command)
{
base.OnCustomCommand(command);
if (command == (int)commands.CloseIt)
{
//Code to call msghook closeSEB function
runRTS("closeSEBService");
f_closeSEB();
}
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// closeSEBService
//
this.ServiceName = "Service1";
}
#endregion
}
}
しかし、コンパイラで、f_closeSEB という名前が現在のコンテキストで終了しないというエラーが発生します。これは、C# を介して DLL ファイルで定義された関数を呼び出す正しい方法ではありませんか?