Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Multi-threaded C++ Client using C# Server - Crash on Exit
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ruth Abraham  
View profile  
 More options Feb 19 2004, 12:44 pm
Newsgroups: microsoft.public.dotnet.framework.interop
From: ruth.abra...@instrumar.net (Ruth Abraham)
Date: 19 Feb 2004 09:44:08 -0800
Local: Thurs, Feb 19 2004 12:44 pm
Subject: Multi-threaded C++ Client using C# Server - Crash on Exit
I have a C++ client using a C# server (with events) via COM interop,
and it crashes on exit with an unhandled access violation in
mscorwks.dll.  There are first-chance access violations in
mscorwks.dll before the crash.  If the client does not attach to the
server's events, then no exceptions (first-chance or unhandled) occur.
 If the client does not call CoInitializeEx with the
COINIT_MULTITHREADED option, no exceptions occur, but my client runs
in a multi-threaded apartment so this is required.

Behaviour is also affected by adding extra private member data to my
Client class along with the smart pointer to the server object, so
there appears to be memory issues.  Creating ten client objects in
main is not required for the program to crash, but this makes the
crash repeatable, not sporadic.

Sample client code
==================

_ATL_FUNC_INFO OnTheEventInfo = {CC_STDCALL, VT_EMPTY, 1, {VT_BSTR}};

class Client : public IDispEventSimpleImpl<1, Client,
&DIID__DEventInterface>
{
public:
    BEGIN_SINK_MAP(Client)
        SINK_ENTRY_INFO(1, DIID__DEventInterface, 1, OnTheEvent,
&OnTheEventInfo)
    END_SINK_MAP()

    void __stdcall OnTheEvent(BSTR aData)
        {
        ::SysFreeString(aData);
        }

    Client(void)
        {
        mspManagedServer = IManagedServerPtr(__uuidof(ManagedServer));
        DispEventAdvise((IUnknown*)mspManagedServer);
        }

    ~Client(void)
        {
        DispEventUnadvise((IUnknown*)mspManagedServer);
        }
private:
    IManagedServerPtr mspManagedServer;
    // Extra data declared here will affect whether or not the program
crashes.

};

int _tmain(int argc, _TCHAR* argv[])
    {
    HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);

    Client lClient1;
    Client lClient2;
    Client lClient3;
    Client lClient4;
    Client lClient5;
    Client lClient6;
    Client lClient7;
    Client lClient8;
    Client lClient9;
    Client lClient10;

    CoUninitialize();

    return 0;
    }

Sample Server Code
==================

using System;
using System.Runtime.InteropServices;

namespace ManagedServer
{
    [Guid("22B65510-6E3F-4f7f-9A98-043BD41655C6")]
    public interface IManagedServer
    {
        void Initialize();
    }

    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    [Guid("2415AE3B-D9CB-4ad1-B7F5-2060F08F24BC")]
    public interface _DEventInterface
    {
        [DispId(1)] void TheEvent(string msg);
    }

    [ComSourceInterfaces(typeof(_DEventInterface))]
    [Guid("CE850092-9CCB-4073-BC0D-DC36DC1DB7BC")]
    [ClassInterface(ClassInterfaceType.None)]
    public class ManagedServer : IManagedServer
    {
        public ManagedServer(){}

        [ComVisible(false)]
        public delegate void MyEventTarget(string msg);

        public event MyEventTarget TheEvent;

        [ComVisible(false)]
        public void FireTheEvent()
        {
            TheEvent("Message from ManagerServer");
        }

        public void Initialize()
        {
            FireTheEvent();
        }
    }

}

The call stack is either:

>    00fc0a18()      

        NTDLL.DLL!ExecuteHandler@20()  + 0x26  
        NTDLL.DLL!_RtlDispatchException@8()  + 0x69    
        NTDLL.DLL!_KiUserExceptionDispatcher@8()  + 0xe

or

>    mscorwks.dll!CtxEntry::Release()  + 0x1

        mscorwks.dll!IUnkEntry::Free()  + 0x6d  
        mscorwks.dll!ComPlusWrapper::ReleaseAllInterfaces()  + 0xa      
        mscorwks.dll!ComPlusWrapper::ReleaseAllInterfacesCallBack()  + 0xae    
        mscorwks.dll!ComPlusWrapper::Cleanup()  + 0x14  
        mscorwks.dll!ComPlusContextCleanupGroup::CleanUpWrappers()  + 0x19      
        mscorwks.dll!ComPlusApartmentCleanupGroup::ReleaseCleanupGroup()  +
0xe
        mscorwks.dll!ComPlusApartmentCleanupGroup::ReleaseCleanupGroupCallback()
 + 0xe9
        mscorwks.dll!ComPlusApartmentCleanupGroup::CleanUpWrappers()  + 0x61

depending on the extra private member data.  Any help or insight would
be much appreciated.  This occurs developing on both Windows 2000 and
Windows XP, using Microsoft Visual Studio .NET 2003 and .NET Framework
1.1.

Thanks,
Ruth


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »