Click here to Skip to main content
15,903,523 members
Home / Discussions / COM
   

COM

 
AnswerRe: BSTR problems in COM Service Pin
Gerald Schwab3-Mar-06 10:02
Gerald Schwab3-Mar-06 10:02 
GeneralRe: BSTR problems in COM Service Pin
RobCraig3-Mar-06 11:58
RobCraig3-Mar-06 11:58 
QuestionHow to detect ActiveX on IE when it begins run using BHO? Pin
Blue-Bird1-Mar-06 21:09
Blue-Bird1-Mar-06 21:09 
QuestionUsing ActiveX in MFC Pin
lroels1-Mar-06 20:36
lroels1-Mar-06 20:36 
Questionout of process activex exe Pin
david_reynolds28-Feb-06 9:16
david_reynolds28-Feb-06 9:16 
AnswerRe: out of process activex exe Pin
Roger Stoltz28-Feb-06 21:23
Roger Stoltz28-Feb-06 21:23 
GeneralRe: out of process activex exe Pin
david_reynolds1-Mar-06 3:11
david_reynolds1-Mar-06 3:11 
QuestionHow to delete a COM object - My Other Code Pin
AmitGG27-Feb-06 22:45
AmitGG27-Feb-06 22:45 
I have a C# (managed code) DLL and I am accessing this DLL's functions from C++ (unmanaged code) using COM.

I create a COM object with CoCreateInstance function. Then I do work on this object. After that I call Release() function on this object. But after calling Release() function the object is not destroyed automatically. After calling Release function I called some more functions on this object and all those calls were successful.

I also checked the return value of Release function call which is ZERO which shows the reference count of the object is ZERO and it should automatically destroy the object as soon as the reference count becomes ZERO. But in my case the object is not destroyed.

Actually in my project work I have to create and destroy the COM object many times (1000-2000). So in each iteration the memory size is increasing and after some iteration it becomes more than 1 GB and fills all the page file space and the program hangs.

Could Anybody suggest me how to delete the COM object. I have also given below the server side code which is in C#.


The client side code which I am using is following :

#import "ServerSideCode.tlb" named_guids high_method_prefix("")
#include <iostream.h>
#include <comdef.h>

using namespace ServerSideCode;

class Test
{

public:
IEnterDetails *pPER1;
IEnterDetails *pPER;
IEnterAge *pAge;
public:
void Func1();
};

void Test::Func1()
{
pPER1 = NULL;
HRESULT hr = CoInitialize(NULL);
hr=CoCreateInstance(__uuidof(Manager), NULL, CLSCTX_INPROC_SERVER,
__uuidof(IEnterDetails), reinterpret_cast<void**>(&pPER1));

pPER1->Print();
long a = pPER1->Release();
a = pPER1->Release();
a = pPER1->Release();
a = pPER1->Release();
// pPER1 = NULL;
pPER1->EnterName();
pPER1->Print();
pPER1->QueryInterface(__uuidof(IEnterAge), reinterpret_cast<void**>(&pAge));
pAge->EnterAge();
pAge->Print();
a = pPER1->Release();
CoUninitialize();
}

void main()
{
Test tt;
tt.Func1();
}







The C# code which was used to build the DLL (ServerSideCode.dll) is the following


using System;
namespace ServerSideCode
{
public interface IEnterDetails
{
void EnterName();
void EnterDesignation();
void EnterIncome1();
void EnterIncome2();
void Add();
void Print();
}
public interface IEnterAge
{
void EnterAge();
void Print();
int Age {get; set;}
}

public class Person : IEnterDetails
{
private string Name = "DefaultName", Des = "DefaultDesignation";
private int inc1=0, inc2=0,inc=0;

public void EnterName()
{
Console.WriteLine("Enter your Name : ");
Name = Console.ReadLine();
}
public void EnterDesignation()
{
Console.WriteLine("Enter your Designation : ");
Des = Console.ReadLine();
}

public void EnterIncome1()
{
Console.WriteLine("Enter your source1 income :");
inc1 = Int32.Parse(Console.ReadLine());
}

public void EnterIncome2()
{
Console.WriteLine("Enter your source2 income :");
inc2 = Int32.Parse(Console.ReadLine());
}

public void Add()
{
inc=inc1+inc2;

}


public void Print()
{
Console.WriteLine("Emplyee Name : {0}", Name);
Console.WriteLine("Employee Designation : {0}", Des);
Console.WriteLine("Income from Source1 : {0} \n Income from Source2 : {1}", inc1, inc2);
Console.WriteLine("Total Income of the Employee : {0}",inc);
}
}

public class Manager: Person, IEnterAge
{
private int age;
public void EnterAge()
{
Console.WriteLine("Enter the Age in years :");
age = Int32.Parse(Console.ReadLine());

}
public int Age
{
get
{
return age;
}
set
{
age = value;
}
}
public void Print()
{
base.Print();
Console.WriteLine("The Age of the Employee : {0}", age);
}

}
}

Please tell me if I am wrong anywhere in my server code.

-- modified at 6:35 Tuesday 28th February, 2006
AnswerRe: How to delete a COM object - My Other Code Pin
AmitGG28-Feb-06 22:14
AmitGG28-Feb-06 22:14 
QuestionHow to delete a COM object Pin
AmitGG27-Feb-06 20:30
AmitGG27-Feb-06 20:30 
AnswerRe: How to delete a COM object Pin
mbue27-Feb-06 22:07
mbue27-Feb-06 22:07 
GeneralRe: How to delete a COM object Pin
AmitGG27-Feb-06 22:21
AmitGG27-Feb-06 22:21 
GeneralRe: How to delete a COM object Pin
mbue27-Feb-06 23:29
mbue27-Feb-06 23:29 
GeneralRe: How to delete a COM object Pin
AmitGG28-Feb-06 0:05
AmitGG28-Feb-06 0:05 
GeneralRe: How to delete a COM object Pin
mbue28-Feb-06 3:51
mbue28-Feb-06 3:51 
QuestionConnecting Multiple clients to single server using DCOM Pin
abhiramsss27-Feb-06 18:21
abhiramsss27-Feb-06 18:21 
AnswerRe: Connecting Multiple clients to single server using DCOM Pin
FearlessBurner6-Mar-06 1:51
FearlessBurner6-Mar-06 1:51 
GeneralRe: Connecting Multiple clients to single server using DCOM Pin
abhiramsss8-Mar-06 19:10
abhiramsss8-Mar-06 19:10 
GeneralRe: Connecting Multiple clients to single server using DCOM Pin
abhiramsss9-Mar-06 23:31
abhiramsss9-Mar-06 23:31 
GeneralRe: Connecting Multiple clients to single server using DCOM Pin
FearlessBurner10-Mar-06 0:18
FearlessBurner10-Mar-06 0:18 
GeneralRe: Connecting Multiple clients to single server using DCOM Pin
abhiramsss12-Mar-06 20:09
abhiramsss12-Mar-06 20:09 
GeneralRe: Connecting Multiple clients to single server using DCOM Pin
abhiramsss13-Mar-06 22:30
abhiramsss13-Mar-06 22:30 
GeneralRe: Connecting Multiple clients to single server using DCOM Pin
FearlessBurner16-Mar-06 4:25
FearlessBurner16-Mar-06 4:25 
GeneralRe: Connecting Multiple clients to single server using DCOM Pin
abhiramsss19-Mar-06 21:24
abhiramsss19-Mar-06 21:24 
GeneralRe: Connecting Multiple clients to single server using DCOM Pin
FearlessBurner22-Mar-06 6:51
FearlessBurner22-Mar-06 6:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.