Click here to Skip to main content
12,823,976 members (41,845 online)
Click here to Skip to main content
Add your own
alternative version

Stats

340.9K views
2.8K downloads
289 bookmarked
Posted 2 Jan 2006

Building COM Servers in .NET

, 2 Feb 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
Learn the fundamental principles of building COM DLL and EXE Servers using a .NET language.
 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Lim Bio Liong
Systems Engineer NEC
Singapore Singapore
Lim Bio Liong is a Specialist at a leading Software House in Singapore.

Bio has been in software development for over 10 years. He specialises in C/C++ programming and Windows software development.

Bio has also done device-driver development and enjoys low-level programming. Bio has recently picked up C# programming and has been researching in this area.

You may also be interested in...

Pro
Pro

Comments and Discussions

 
QuestionHow to provide server events to C++ COM client ? Pin
Gonzalezz25-Aug-09 23:41
memberGonzalezz25-Aug-09 23:41 
Hello Bio,
thanks for useful article !

I've got a problem: COM client can't resive the events from server because can't find connection point.
Server side (like ManagedCOMLocalServer_Impl01):

[
    Guid("E1828CD3-CB6C-4ed0-B56E-839C6A38D0F1"),
    ProgId("ManagedCOMLocalServer.ServerObject"),
    ClassInterface(ClassInterfaceType.None)
]
public class ServerObject : ReferenceCountedObjectBase, IServerObject, _IServerObjectEvents
{
   public event _IServerObjectEvents_DataRecivedEventHandler DataRecived;

   public void Start()
   {
       if (DataRecived != null)
           DataRecived();
   }

   void _IServerObjectEvents.DataRecived()
   {
   }
}


Client side (like CPPClient01):

#import "C:\ServerObject.tlb" named_guids // from ATL project

int _tmain(int argc, _TCHAR* argv[])
{
    IServerObjectPtr spIServerObject = NULL;
    CreateInstanceByClassFactory<IServerObjectPtr> ...
    ....
    CComPtr<IConnectionPoint> spConnectionPoint;
    CComPtr<IConnectionPointContainer> spConnectionPointContainer;
    hr = spIServerObject->QueryInterface(IID_IConnectionPointContainer,(void **)&spConnectionPointContainer); // S_OK
    if(SUCCEEDED(hr)) 
    {
        hr = spConnectionPointContainer->FindConnectionPoint(DIID__IServerObjectEvents, &spConnectionPoint);  // -2147220992  Why ?
        if(SUCCEEDED(hr)) 
        {  ....  }
    }
    ....
}

ServerObject.idl file:

[
	object,
	uuid(D7F398AB-7A1A-4FE1-B8D8-2187C9099E59),
	dual,
	nonextensible,
	helpstring("IServerObject Interface"),
	pointer_default(unique)
]
interface IServerObject : IDispatch{
	[id(1), helpstring("method Start"), helpcontext(1)] HRESULT Start();
	
};
[
	uuid(6167E0E8-4BEF-4CA8-B510-A88873842DC2),
	version(1.0),
	helpstring("ServerInterface 1.0 Type Library")
]
library ServerObjectLib
{
	importlib("stdole2.tlb");
	[
		uuid(CC6E263B-7AE8-4A4B-BB02-EE22F1F508D9),
		helpstring("_IServerObjectEvents Interface")
	]
	dispinterface _IServerObjectEvents
	{
		properties:
		methods:
			[id(1)] void DataRecived();
	};
	[
		uuid(C92B818E-29FC-4ABD-AE28-ADC8D6C7344B),
		helpstring("ServerObject Class")
	]
	coclass ServerObject
	{
		[default] interface IServerObject;
		[default, source] dispinterface _IServerObjectEvents;
	};
};

Do you know how resolve this problem? Is it possible for exe server (dll work fine)?

Regards,
Gonzalezz

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 2 Feb 2006
Article Copyright 2006 by Lim Bio Liong
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid