hi guys,

please anyone tell step by step tutorial on COM using vs2005.

Dani AI

Generated

— first clarify whether you want to create a COM component or just use one. As hinted, the workflows are different; is right that many tutorials exist, but the shortest practical path for VS2005/C++ is either ATL for creating servers or simple client-side use with CoCreateInstance/#import.

For creating a COM server with VS2005 (high level)

  1. New -> Project -> ATL Project (choose DLL for in-process)
  2. Add -> Class -> ATL Simple Object (wizard generates IDL, .idl/.tlb, and registration scripts)
  3. Implement your methods and interfaces (decide IDispatch/dual if you need scripting support; otherwise use a custom vtable interface inheriting IUnknown)
  4. Build and register the DLL (VS can register on build or use regsvr32)
  5. Test with OLE/COM Object Viewer or a simple client.

For consuming a COM object from C++ (high level)

  1. Initialize COM: CoInitializeEx(NULL, COINIT_APARTMENTTHREADED) (or MTA as needed)
  2. Create the object: CoCreateInstance or use #import "MyServer.tlb" to get smart wrappers
  3. Use smart pointers (CComPtr<T>) or raw interface pointers and Release()
  4. Call CoUninitialize() when done.

Quick client example:

CoInitialize(NULL);
CComPtr<IMyInterface> sp;
HRESULT hr = sp.CoCreateInstance(CLSID_MyComClass);
if (SUCCEEDED(hr)) sp->MyMethod();
CoUninitialize();

Common pitfalls and checks

  • “Class not registered” (REGDB_E_CLASSNOTREG): ensure the DLL/EXE is registered and matches process bitness (x86 vs x64).
  • Threading model mismatches cause RPC/E_CHANGED_MODE; pick STA vs MTA correctly.
  • UAC can block registration; run elevated to register.
  • Use oleview.exe to inspect type libraries and registry entries and guidgen to create GUIDs.

Authoritative references:

Recommended Answers

All 3 Replies

You mean to create one or use one

Here is a tutorial:


The title says, Step by Step COM Tutorial

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.