Click here to Skip to main content
16,004,778 members
Home / Discussions / COM
   

COM

 
AnswerRe: How to access Variant type 8204 Pin
Vi224-Jul-09 1:57
Vi224-Jul-09 1:57 
GeneralRe: How to access Variant type 8204 Pin
BeerFizz24-Jul-09 2:59
BeerFizz24-Jul-09 2:59 
GeneralRe: How to access Variant type 8204 Pin
Vi227-Jul-09 0:27
Vi227-Jul-09 0:27 
QuestionCom BHO In Vista/IE7 Pin
abhi11shukla23-Jul-09 2:39
abhi11shukla23-Jul-09 2:39 
QuestionVirtual PC and COM Server Pin
gehbitte22-Jul-09 2:41
gehbitte22-Jul-09 2:41 
AnswerRe: Virtual PC and COM Server Pin
Stuart Dootson22-Jul-09 7:04
professionalStuart Dootson22-Jul-09 7:04 
GeneralRe: Virtual PC and COM Server Pin
gehbitte22-Jul-09 7:14
gehbitte22-Jul-09 7:14 
QuestionProblem passing interface pointer from COM server to .NET Client Pin
mbet87821-Jul-09 3:32
mbet87821-Jul-09 3:32 
Hello everyone,

I have written a small test application. The application is splitted into two parts. The first part is written in unmanaged C++ using ATL. It creates a normal window in which a .NET control will be loaded using the class ATL::CAxWindow. Besides two interfaces (IExtensionInfo, ITreeItem) and TreeItem coclass are defined in the library.
The second part is a C# class library containing one UserControl. The C# part references the type library from the part written in C++.

Here is an small overview.

C# Part: class Extension : UserControl, IExtensionInfo

C++ Part:
class CMainWindow
class CTreeitem : ITreeItem

And here is the IDL code for the interfaces.
interface ITreeItem : IDispatch
{
	HRESULT AddChild(void);
	HRESULT GetChildCount([out,retval] LONG* pChildCount);
};
interface IExtensionInfo : IUnknown
{
	HRESULT GetCaption([out, retval] BSTR* caption);
	HRESULT SetCaption([in] BSTR caption);
	HRESULT Init([in] ITreeItem* ipTreeItem);
	HRESULT Unload(void);
};


Now we came to the core part: Creating the C# control and host it in a container; Creating a TreeItem object and passing the interface pointer to the C# part.
When the Init method is not called to pass the interface pointer to the C# control then everything is doing just fine. But when it is called then the application remains in memory after the window is closed.

LRESULT CMainWindow::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	HRESULT hr;
	_AtlModule.Lock();
	
	this->m_pCtrlWindow = new CAxWindow();
	// Get rect of visible area.
	RECT rect;
	this->GetClientRect(&rect);
	// Create control window.
	HWND hControlWindow = this->m_pCtrlWindow->Create(this->m_hWnd, rect, NULL, WS_CHILD | WS_VISIBLE);
	
	IUnknown *pUnknownControl;
	// Load the control via the ProgID.
	hr = this->m_pCtrlWindow->CreateControlEx(L"CsControlInNativeWindow.Extension", NULL, NULL, &pUnknownControl);
	this->m_spExtensionInfo = pUnknownControl;
	if (pUnknownControl)
	{
		pUnknownControl->Release();
	}
	
	// Create a TreeItem COM object which the Extension can access.
	this->m_spTreeItem.CoCreateInstance(CLSID_TreeItem);
	this->m_spExtensionInfo->Init(this->m_spTreeItem);
	
	return 0;
}

LRESULT CMainWindow::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	if (this->m_spTreeItem)
	{
		this->m_spTreeItem.Release();
	}
	
	if (this->m_spExtensionInfo)
	{
// Inform the control that we do not need it anymore.
		this->m_spExtensionInfo->Unload();
		this->m_spExtensionInfo.Release();
	}

	if (this->m_pCtrlWindow)
	{
		this->m_pCtrlWindow->DestroyWindow();
		delete this->m_pCtrlWindow;
		this->m_pCtrlWindow = NULL;
	}
	
	_AtlModule.Unlock();
	return 0;
}



I hope someone can tell me how I can make that the application shuts down.

Best regards.
Questiontext to speech Pin
koohbor_farhad32320-Jul-09 5:09
koohbor_farhad32320-Jul-09 5:09 
AnswerRe: text to speech Pin
Stuart Dootson20-Jul-09 23:26
professionalStuart Dootson20-Jul-09 23:26 
AnswerRe: text to speech Pin
benjymous27-Jul-09 22:47
benjymous27-Jul-09 22:47 
Questionusing com dll without registering it Pin
Ash_VCPP20-Jul-09 3:06
Ash_VCPP20-Jul-09 3:06 
AnswerRe: using com dll without registering it Pin
«_Superman_»20-Jul-09 19:56
professional«_Superman_»20-Jul-09 19:56 
GeneralRe: using com dll without registering it Pin
Md. Marufuzzaman25-Jul-09 18:52
professionalMd. Marufuzzaman25-Jul-09 18:52 
QuestionHow to Start Scanner and Camera wizard to import pictures by code? Pin
linova20-Jul-09 2:30
linova20-Jul-09 2:30 
QuestionObject doesn't support this property or method Pin
peace_smyle16-Jul-09 4:01
peace_smyle16-Jul-09 4:01 
AnswerRe: Object doesn't support this property or method Pin
Hristo-Bojilov16-Jul-09 9:12
Hristo-Bojilov16-Jul-09 9:12 
GeneralRe: Object doesn't support this property or method Pin
peace_smyle16-Jul-09 19:11
peace_smyle16-Jul-09 19:11 
QuestionID3DX10Mesh and ID3DXMesh Guids EXACTLY the same [modified] Pin
Klempie16-Jul-09 2:28
Klempie16-Jul-09 2:28 
AnswerRe: ID3DX10Mesh and ID3DXMesh Guids EXACTLY the same Pin
Randor 16-Jul-09 10:44
professional Randor 16-Jul-09 10:44 
GeneralRe: ID3DX10Mesh and ID3DXMesh Guids EXACTLY the same Pin
Klempie16-Jul-09 11:08
Klempie16-Jul-09 11:08 
GeneralRe: ID3DX10Mesh and ID3DXMesh Guids EXACTLY the same Pin
Baltoro16-Jul-09 15:03
Baltoro16-Jul-09 15:03 
GeneralRe: ID3DX10Mesh and ID3DXMesh Guids EXACTLY the same Pin
Klempie16-Jul-09 22:55
Klempie16-Jul-09 22:55 
QuestionLow Level Drive Hooks Pin
saif_saifi14-Jul-09 20:18
professionalsaif_saifi14-Jul-09 20:18 
AnswerRe: Low Level Drive Hooks Pin
Randor 15-Jul-09 13:00
professional Randor 15-Jul-09 13:00 

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.