BOOL CSpcLocalApp::InitInstance()
{
...
// {
if (!AfxOleInit()) {
AfxMessageBox("Could not initialize OLE subsystem.");
return FALSE;
}
// }
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// {
CCommandLineInfo CmdInfo;
ParseCommandLine(CmdInfo);
// Check to see if launched as OLE server
if (CmdInfo.m_bRunEmbedded || CmdInfo.m_bRunAutomated)
{
// Application was run with /Embedding or /Automation.
// Register all OLE server (factories) as running. This enables the
// OLE libraries to create objects from other applications.
COleObjectFactory::RegisterAll();
return TRUE;
}
VOID CSpcLocalApp::RegisterComponent(const CString &strProgID)
{
// Place the server into the system registry
COleObjectFactory::UpdateRegistryAll();
CString strMsg;
strMsg += "The " + strProgID + " server has been registered.";
AfxMessageBox(strMsg, MB_ICONINFORMATION);
}
VOID CSpcLocalApp::UnregisterComponent(const CString &strClassID, const CString &strProgID)
{
// Transform the string-format CLASSID into a real CLSID
CLSID CLSID_Component;
BSTR bstrClassID = strClassID.AllocSysString();
CLSIDFromString(bstrClassID, &CLSID_Component);
SysFreeString(bstrClassID);
// Unregister the class
AfxOleUnregisterClass(CLSID_Component, strProgID);
CString strMsg;
strMsg += "The " + strProgID + " server has been registered.";
AfxMessageBox(strMsg, MB_ICONINFORMATION);
}
import "wtypes.idl";
import "unknwn.idl";
[
object,
uuid(2C1FDBD6-556B-4a50-B63C-F2B64A6DDC38),
helpstring("ISimpleCal interface"),
pointer_default(unique)
]
interface ISimpleCal:IUnknown
{
HRESULT Sum ([in] int x, [in] int y, [out]int* z);
HRESULT Sub ([in] int x, [in] int y, [out]int* z);
};
//
// Class information for SimpleCal
//
[ uuid(45C971F6-3A78-4163-A994-FDBB6894F4B2) ]
coclass COMPONENT
{
interface ISimpleCal;
};
class CSimpleCalc : public CCmdTarget
{
public:
// Constructor
CSimpleCalc();
// Destructor
virtual ~CSimpleCalc();
protected:
BEGIN_INTERFACE_PART(CInnerSimpleCal, ISimpleCal)
STDMETHOD(Sum)(int x, int y, int* z);
STDMETHOD(Sub)(int x, int y, int* z);
END_INTERFACE_PART(CInnerSimpleCal)