- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个关于 Windows 服务的非常基本的问题,我有这个安装的 main
函数,我可以用它来安装我的服务,还有一些配置数据加载到 main 函数中:
int
wmain(int argc, WCHAR* argv[])
{
// it reads config and fill a global struct.
ReadConfig();
// if command == 'install'
install_service();
}
这是服务的主要功能:
void WINAPI ServiceMain(DWORD argc, WCHAR* argv[])
{
// this method retrieves the global config object.
auto config_data = GetConfigData();
// service stuff
}
这是在我的 wmain
函数中调用的另一个函数,如果它在没有任何参数的情况下运行 (argc = 0 !):
bool
ServiceRunAsService()
{
static const SERVICE_TABLE_ENTRY table[] = {
{ SERVICE_NAME, ServiceMain },
{ NULL, NULL }
};
g_hStopService = CreateEvent(0, TRUE, FALSE, 0);
return StartServiceCtrlDispatcher(table) && GetLastError() != ERROR_FAILED_SERVICE_CONTROLLER_CONNECT;
}
我的问题是,当 Windows 想要运行我的服务时(在 PC 关闭并再次打开之后),它是否调用了我的 wmain
函数(因此调用了 ReadConfig
函数)还是调用注册的ServiceMain
函数?我想指出 install_service
方法,通过 GetModuleFileName
找到可执行文件的路径并将其传递给 CreateService
和 ScmManager
最佳答案
当可执行文件启动时,无论出于何种原因,都会调用 exe 入口点(如果进程之前没有崩溃或 Hook )。所以在你的情况下总是调用你的wmain
的wmainCRTStartup
(或者你的exe真正入口点的名称是什么)。所以是的 - 每次可执行文件启动时都会调用您的 wamin
。
而且系统根本无法调用ServiceMain
。它根本不知道它的地址。它没有注册。当您注册 exe 服务时,您注册了服务的命令行,但没有在 exe 中注册任何导出的名称。您的可执行文件成为服务并仅在 StartServiceCtrlDispatcher
之后注册 ServiceMain
,它必须从您的 wmain
即使 dll 形式的服务与 svchost.exe
一起工作 - 您注册导出的函数,它必须从您的 dll 调用作为服务入口点,或者默认情况下 ServiceMain
.但无论如何,即使在这种情况下,首先你的 DllMain
(dll 入口点)将被调用(如果存在)。如果是 exe - 入口点是强制性的并且总是会被调用
关于c++ - 是否每个 Windows 服务都调用其可执行的 main 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53462047/
所以问题是:如何使用标准 C 库以跨平台方式实现简单的自检可执行文件? 在这里,我正在寻找技术,而不是特定的检查方法(如 CRC 或哈希码),但该技术可能包含更适合某些方法的元素(例如见下文)。 目的
我想构建一个 C++ 可执行文件,以便所有库也附加到可执行文件。构建这样一个可执行文件的方法是什么?因此,每当我在其他 PC(运行 Ubuntu)上使用 g++ 编译我的代码时,它不需要运行该可执行文
我在 Netbeans IDE 8.0.1 中编写了一个名为 SampleChat 的 Java GUI 程序,并使用“clean and build”功能创建了一个 jar 文件。 我进入 Netb
我有两个 DLL,一个用 native C++ 编写,另一个用 C++/CLI 编写。前者被注入(inject)到进程中,并在稍后的时间点加载后者。在调试时,我注意到 native DLL 的断点运行
如何访问可执行文件的机器代码(二进制文件)? 详情 我使用的是 Ubuntu (Linux) 我想访问 .exe 文件(文件遵循 PE 格式)的机器代码(二进制文件) 我正在使用 C 来实现 最佳答案
这个问题在这里已经有了答案: Run java jar file on a server as background process (4 个回答) 关闭1年前. 我正在使用命令提示符运行一个可执行
我的 jar 没有运行,我可以告诉它尝试运行,因为 log4j 文件设法创建日志文件夹,但没有任何 react 并且日志为空白。 我的问题是我在名为 bin 的文件夹中有 jar 文件,在名为 lib
我正在为我教育第一学期的编程考试创建一个程序。它应该向用户显示哥本哈根和其他 6 个城市(在其他时区)的时间。用户还应该能够将城市添加到列表中。我正在用 JAVA 编写程序(下面提供源代码)。当我从
我正在查看雅虎的 YUI 压缩器可执行 jar,他们有这个类,从 list 文件链接为“主类”: package com.yahoo.platform.yui.compressor; import j
问题是:从 Eclipse 导出时可执行 jar 中包含什么?我问这个问题是因为我想知道,例如,如果我在项目根目录中有一个图像,该图像是否会包含在导出中? 澄清:我说的是可运行的 jar 文件(已编辑
我知道这个问题已经被问了很多,并且我已经尝试了 eclipse(Kepler、Ganymede、Galileo)、fatJar、netbeans、blueJ、命令行和手册中的大约 20-30 种不同的
我从 IntelliJ 14.03 中的一个工件构建了一个 .jar。当我尝试在 JRE 中打开它时,没有任何反应。这只是一个简单的 GUI。 提前致谢。 最佳答案 在jar位置运行命令,例如 jav
我使用 eclipse 创建了一个可执行 JAR 文件。我在项目文件夹中有资源当框架打开时不会出现。我的意思是当我双击 JAR 文件时。更多的所以,在我尝试删除 JAR 文件后,我收到一条警告,表明该
我创建了一个尺寸相当大(125,000 kb)的可运行 Jar 文件。当我运行它时,该 jar 文件内的应用程序不会显示,但在任务管理器中 javaw.exe(应链接到该 jar 文件)进程正在运行。
我已经使用 Eclipse(文件->导出)为我的 java 程序创建了一个可执行 jar 文件。 当我双击 jar 时,它工作正常。将 jar 文件复制到另一台计算机(Windows)后,我收到错误“
我用 eclipse indigo 创建了一个可执行的 jar 文件,但是当我双击它时什么也没有发生。但是当我将 java -jar c:/dir/filename.jar 写入 cmd 时,它可以工
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭10 年前。 Improve th
如何让该 Java 代码在 Eclipse 之外运行? import java.util.*; public class Calculations { public static void main(
今天我第一次启动 jar 文件时遇到问题。现在我知道(解压 jar 后)当我在 Eclipse 中导出并创建程序的 jar 包时,文本文件并没有出现。 为什么文本文件没有与类文件一起出现?我应该将它们
我不知道为什么,但是当我将项目导出到可执行 jar 文件时,有些东西并不像从 eclipse 运行程序一样。一帧不会打开,其中只包含文本。我有另一个内部框架,它是一个分割 Pane ,包含右侧面板上的
我是一名优秀的程序员,十分优秀!