Skip to content

Commit 923f0df

Browse files
committed
MyExeServerCpp: Call CoAddRefServerProcess when started without arguments
Done to ensure that the COM server outlives any connected clients.
1 parent c11377a commit 923f0df

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

MyExeServerCpp/Main.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,18 @@ MyserverModule _AtlModule;
2929

3030

3131
// EXE Entry Point
32-
int wmain(int /*argc*/, wchar_t* /*argv*/[]) {
32+
int wmain(int argc, wchar_t* /*argv*/[]) {
3333
// initialize COM early for programmatic COM security
3434
_AtlModule.InitializeCom();
3535
HRESULT hr = _AtlModule.InitializeSecurity();
3636
if (FAILED(hr))
3737
abort();
3838

39+
if (argc == 1) {
40+
// process started without arguments
41+
// add an artificial reference to make the server outlive COM clients
42+
CoAddRefServerProcess();
43+
}
44+
3945
return _AtlModule.WinMain(SW_SHOWDEFAULT);
4046
}

0 commit comments

Comments
 (0)