This is a coding exercise I am currently working on to get myself familiarized with COM.
https://www.codeproject.com/Articles/8679/Building-a-LOCAL-COM-Server-and-Client-A-Step-by-S
https://adapt-and-attack.com/2020/05/12/building-a-com-server-for-initial-execution/
import "oaidl.idl";
// define IStats interface
[object, uuid(FE78387F-D150-4089-832C-BBF02402C872),
oleautomation, helpstring("Get the status information about this car")]
interface IStats : IUnknown
{
HRESULT DisplayStats();
HRESULT GetPetName([out,retval] BSTR* petName);
};
// define the IEngine interface
[object, uuid(E27972D8-717F-4516-A82D-B688DC70170C),
oleautomation, helpstring("Rev your car and slow it down")]
interface IEngine : IUnknown
{
HRESULT SpeedUp();
HRESULT GetMaxSpeed([out,retval] int* maxSpeed);
HRESULT GetCurSpeed([out,retval] int* curSpeed);
};
// define the ICreateMyCar interface
[object, uuid(5DD52389-B1A4-4fe7-B131-0F8EF73DD175),
oleautomation, helpstring("This lets you create a car object")]
interface ICreateMyCar : IUnknown
{
HRESULT SetPetName([in]BSTR petName);
HRESULT SetMaxSpeed([in] int maxSp);
};
// library statement
[uuid(957BF83F-EE5A-42eb-8CE5-6267011F0EF9), version(1.0),
helpstring("Car server with typeLib")]
library CarLocalServerLib
{
importlib("stdole32.tlb");
[uuid(1D66CBA8-CCE2-4439-8596-82B47AA44E43)]
coclass MyCar
{
[default] interface ICreateMyCar;
interface IStats;
interface IEngine;
};
};
// Interface
[
object,
uuid(44568f24-d895-42a4-97ee-db91c60cc1c4),
helpstring("Leos Test Class"),
pointer_default(unique),
dual,
oleautomation
]
interface ITestClass : IDispatch
{
import "oaidl.idl";
HRESULT SetData([in] BSTR data);
HRESULT Run();
};
// Type Library
[
uuid("44568f25-d895-42a4-97ee-db91c60cc1c4"),
version(1.0),
helpstring("TestClass Type Library")
]
library TestClassLib
{
importlib("stdole32.tlb");
[
uuid("44568f26-d895-42a4-97ee-db91c60cc1c4"),
helpstring("TestClass Component Class")
]
coclass TestClass
{
[default] interface ITestClass;
};
};
//IUnknown
ULONG __stdcall AddRef();
ULONG __stdcall Release();
HRESULT __stdcall QueryInterface(REFIID riid, void** ppv);
// IDispatch
HRESULT __stdcall GetTypeInfoCount(UINT* pctinfo);
HRESULT __stdcall GetTypeInfo(UINT iTypeInfo, LCID, ITypeInfo** ppTypeInfo);
HRESULT __stdcall GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID, DISPID* rgDispId);
HRESULT __stdcall Invoke(DISPID dispIdMember, REFIID riid, LCID, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr);
// ITestClass
HRESULT __stdcall SetData(wchar_t* data);
HRESULT __stdcall Run();
https://learn.microsoft.com/en-us/windows/win32/midl/data-types-in-the-interface-body