Using UnManaged Code in Managed code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Usman Jamil

    Using UnManaged Code in Managed code

    Hi

    I've a COM written in VC++ 6, and i'm using it in a C# project. I add the
    Com reference in the refrences and in a method of a class of C# code, I
    instantiate the COM object. Since this object is local to the function so it
    should be distroyed as its scope finishes i.e. as the function body
    finishes. and when the COM object destroys, its FinalRelease should be
    called. I've written some cleanup code in this FinalRelease. that is
    important to be executed on its release. But the problem is that the object
    does not get destroyed here, rather it is destroyed when that C# application
    ends. and then the FinalRelease is called. To make things worse, this C#
    application is a non-stopping server type of application that does not get
    exited, so the Object never gets released. It only gets released when I stop
    this server manually. I want this FinalRelease to be called as soon as the
    body of the C# function containing this object finishes. Is there any way I
    can do this.

    Please Help.

    Thanx and Regards

    Usman Jamil


  • Patrice

    #2
    Re: Using UnManaged Code in Managed code

    IMO you'll have to call ReleaseComObjec t :


    Remember that .NET does not have deterministic finalization...

    Patrice

    --

    "Usman Jamil" <usman@advcomm. net> a écrit dans le message de
    news:uzAP5EXKFH A.656@TK2MSFTNG P14.phx.gbl...[color=blue]
    > Hi
    >
    > I've a COM written in VC++ 6, and i'm using it in a C# project. I add the
    > Com reference in the refrences and in a method of a class of C# code, I
    > instantiate the COM object. Since this object is local to the function so[/color]
    it[color=blue]
    > should be distroyed as its scope finishes i.e. as the function body
    > finishes. and when the COM object destroys, its FinalRelease should be
    > called. I've written some cleanup code in this FinalRelease. that is
    > important to be executed on its release. But the problem is that the[/color]
    object[color=blue]
    > does not get destroyed here, rather it is destroyed when that C#[/color]
    application[color=blue]
    > ends. and then the FinalRelease is called. To make things worse, this C#
    > application is a non-stopping server type of application that does not get
    > exited, so the Object never gets released. It only gets released when I[/color]
    stop[color=blue]
    > this server manually. I want this FinalRelease to be called as soon as the
    > body of the C# function containing this object finishes. Is there any way[/color]
    I[color=blue]
    > can do this.
    >
    > Please Help.
    >
    > Thanx and Regards
    >
    > Usman Jamil
    >
    >[/color]


    Comment

    Working...