我正在开发一个具有不同组件的C++项目.我们需要将应用程序作为Windows服务启动.该项目是非托管C++代码.我写了一个C#windows服务,还有一个C风格的dll,它有一个启动不同组件的功能,另一个用来阻止它们.该DLL有两个文件,一个头文件和一个.cpp文件:RTSS.h:
namespace PFDS
{
extern "C" __declspec(dllexport) int runRTS(char*);
}
Run Code Online (Sandbox Code Playgroud)
RTSS.cpp:
using namespace PFDS;
/* ... includes and declarations */
extern "C" __declspec(dllexport) int runRTS(char* service_name)
{
g_reserved_memory = (char*) malloc(sizeof(char) * RESERVED_MEMORY_SIZE);
_set_new_handler(memory_depletion_handler);
// this function is from a C++ .lib which is included in
// the linker input for the RTSS dll project setting.
// SetUnhandledExceptionHandler("RTS");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在Windows服务的ServiceBase子类中,我有以下内容:
[DllImport("RTSSd.dll")]
public static extern int runRTS(string serviceName);
protected override void OnStart(string[] args)
{
try
{
// the bin …Run Code Online (Sandbox Code Playgroud)