IOPCSyncIO::Read method appears to steal Windows messages from host windows|Classic OPC: DA, A&E, HDA, XML-DA, etc.|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
IOPCSyncIO::Read method appears to steal Windows messages from host windows
Avatar
Sam Norris
New Member
Members
Forum Posts: 2
Member Since:
09/23/2022
sp_UserOfflineSmall Offline
1
09/23/2022 - 13:51
sp_Permalink sp_Print

Our application is getting a MessageBeep while inside calls to IOPCSyncIO::Read.  This happens while trying to restore the app from icon by mouse click.  Debugger shows that MessageBeep occurs outside of our code (i.e. inside IOPCSyncIO or related code).

As a test/proof, I forced the message pump to be flushed before messages can be “stolen” by OPC.  With the following code hacked in, I no longer get MessageBeeps and I’m able to restore app from icon:

MSG msg;

while (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))

   {

   TranslateMessage(&msg);

   DispatchMessage(&msg);

   }

hRet = pSyncIO->Read(OPC_DS_DEVICE, dwItemCount, phItems, &pItemStates, &pErrors);

Flushing the message pump shouldn’t be necessary.  Has anyone else encountered this and is there a solution?

I’m not sure which version of OPC is in use for us (we’re quite an old product).  From reading the forums it seems to be the Classic version of OPC client and a look in C:\Program Files (x86)\OPC Foundation\NuGetPackages shows version 2.1.107 (if this is relevant).

Any help would be appreciated.

Sam

Avatar
Randy Armstrong
Admin
Forum Posts: 1578
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
09/23/2022 - 14:05
sp_Permalink sp_Print

Single Threaded COM Applications (STA) run the Windows Message Loop while blocked waiting for I/O.

Try switching to async i/o or a multi-threaded appartment MTA.

Avatar
Sam Norris
New Member
Members
Forum Posts: 2
Member Since:
09/23/2022
sp_UserOfflineSmall Offline
3
09/23/2022 - 14:40
sp_Permalink sp_Print

If by “runs the Windows Message Loop” you mean it calls PeekMessage followed by TranslateMessage and DispatchMessage, then I’d be fine.  Problem seems to be that the messages are not being dispatched and so get lost.

Avatar
Randy Armstrong
Admin
Forum Posts: 1578
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
4
09/24/2022 - 05:42
sp_Permalink sp_Print sp_EditHistory

What is does exactly is internal to the Microsoft code.

As I mentioned above it is probably a STA/MTA issue where a sync COM call blocks the message loop.

Try async i/o on a MTA.

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online:
Guest(s) 31
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1444
Posts: 4887