I'm currently exploring the process of creating a COM Class, and I've run into an issue regarding the DllGetClassObject function. When attempting to create a COM object, I've encountered an error message that states:
1>dlldata.obj : error LNK2005: _DllGetClassObject@12 already defined in BasicComShapesDll.obj
1> Creating library E:\Projects\Visual Studio\ComSession\BasicComShapesDll\Release\BasicComShapesDll.lib and object E:\Projects\Visual Studio\ComSession\BasicComShapesDll\Release\BasicComShapesDll.exp
1>E:\Projects\Visual Studio\ComSession\BasicComShapesDll\Release\BasicComShapesDll.dll : fatal error LNK1169: one or more multiply defined symbols found
1>Done building project "BasicComShapesDll.vcxproj" -- FAILED.
Here is a description of the steps I've taken and the code I'm working with:
I'm using MIDL to generate the DLLData.c file. The contents of the MIDL file are as follows:
import "oaidl.idl";
import "ocidl.idl";
[object,uuid(187c17c8-d5fb-4599-ac9d-75747fbdb964)]
interface IShape : IUnknown {
HRESULT Draw();
};
[object,uuid(73f12c63-0466-4e09-aee0-8ffe6cc4dfcb)]
interface ICircle : IShape {
HRESULT GetRadius([out] double* radius);
};
[object,uuid(4fae6fed-52ca-4069-8eaf-54f09b40f4a8)]
interface ISquare : IShape {
HRESULT GetSideLength([out] double* sideLength);
};
[uuid(2f2b7408-b102-49ea-bdd3-81c9b74fca15)]
coclass CSquare {
[default] interface ISquare;
};
[uuid(87166cdd-6a6f-4276-979d-f99dfec7d97d)]
coclass CCircle {
[default] interface ICircle;
};
[uuid(1e899be1-dea5-4fcb-8dfc-2458a36e4052)]
coclass CShapeFactory {
[default] interface IClassFactory;
};
HRESULT __stdcall CoShapeCreator(IID shapeInterface, PVOID* shape);
I've tried registering the DLL without implementing DllGetClassObject, but I encountered the CLASS_E_CLASSNOTAVAILABLE ClassFactory cannot supply requested class error, indicating that the ClassFactory cannot supply the requested class.
I would greatly appreciate any assistance in resolving this issue. Thank you for your help!