Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6112285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:43:41+00:00 2026-05-23T14:43:41+00:00

I have a com server that is started in the following way: extern C

  • 0

I have a com server that is started in the following way:

extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, 
    HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/)
{
    lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT

#if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)
    HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);
#else
    HRESULT hRes = CoInitialize(NULL);
#endif
    _ASSERTE(SUCCEEDED(hRes));
    _Module.Init(ObjectMap, hInstance, &LIBID_EXACTACONSOLIDATIONLib);
    _Module.dwThreadID = GetCurrentThreadId();
    TCHAR szTokens[] = _T("-/");

    int nRet = 0;
    BOOL bRun = TRUE;
    LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
    while (lpszToken != NULL)
    {
        if (lstrcmpi(lpszToken, _T("UnregServer"))==0)
        {
            _Module.UpdateRegistryFromResource(IDR_ExactaConsolidation, FALSE);
            nRet = _Module.UnregisterServer(TRUE);
            bRun = FALSE;
            break;
        }

        if (lstrcmpi(lpszToken, _T("RegServer"))==0)
        {
            _Module.UpdateRegistryFromResource(IDR_ExactaConsolidation, TRUE);
            nRet = _Module.RegisterServer(TRUE);
            bRun = FALSE;
            break;
        }

        lpszToken = FindOneOf(lpszToken, szTokens);
    }
    if (bRun)
    {
        _Module.StartMonitor();

        #if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)

        hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, 
            REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED);
        _ASSERTE(SUCCEEDED(hRes));
        hRes = CoResumeClassObjects();

        #else

        hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, 
            REGCLS_MULTIPLEUSE);

        #endif

        _ASSERTE(SUCCEEDED(hRes));

        MSG msg;
        while (GetMessage(&msg, 0, 0, 0))
            DispatchMessage(&msg);

        _Module.RevokeClassObjects();
        Sleep(dwPause); //wait for any threads to finish
    }
}

My question is if multiple clients are connected to this COM Server does it process the requests (function calls to the com object that the com server is hosting) in a synchronous fashion?

The reason I ask is because of the following scenario:
Client A and Client B both connect to Com Server C. They both issue a request and this request involves using the COM Object to retrieve the next item (order in my case) from the database. No two clients should be allowed to have the same item so what basically happens is each item is marked as taken when it’s retrieved from the database and returned to the client.

Is it sufficient in the scenario above to mark the item in the database as taken without worrying about race conditions if it’s 2 clients connecting to the same COM server? If the requests are processed synchronously I would think this would be ok to just mark the item as taken.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:43:41+00:00Added an answer on May 23, 2026 at 2:43 pm

    This depends on whether the thread registering (or, rather, creating) the class objects is a Single Threaded Apartment or Multi-Threaded Apartment. See the MSDN article on the threading modes. If you initialized COM with CoInitialize(NULL) or CoInitializeEx(NULL, COINIT_APARTMENTTHREADED), you’re in a STA; if you used CoInitializeEx(NULL, COINIT_MULTITHREADED) or CoInitializeEx(NULL, 0), you’re in a MTA.

    If you’re in a MTA, COM will make multiple calls to your objects at the same time from a thread pool. In a STA, only one call will be made at a time. If you just want to avoid races, using a STA can be a reasonable approach; keep in mind that this will create a performance bottleneck, however, so for very high volume servers, or servers where requests may take a while, using a MTA with your own synchronization logic may be preferable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider a situation. I have an in-proc COM server that contains two COM classes.
I have a COM outproc server written in ATL that registers itself using _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER,
If I have example.com/dir and dir is basically a folder in the example.com server,
Say we have an out-proc COM server and a client. The client calls a
I have a domain foo.com on server bar. I have a subdomain api.foo.com which
I have a base URL : http://my.server.com/folder/directory/sample And a relative one : ../../other/path How
HI I have a URL var str:String = conn=rtmp://server.com/service/&fileId=myfile.flv or var str:String = fileId=myfile.flv&conn=rtmp://server.com/service/
Say I have a htaccess file shared by dev.server and server.site.com. The first domain
I have a solution based on ASP, VB6, COM and SQL Server. The web
I have a table in SQL Server 2005. alt text http://www.techpint.com/sites/default/files/images/table.JPG I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.