- buildcomserversindotnet_src.zip
- CSharpExeCOMServers
- IDotNetClassFactory
- clients
- CPPClient01
- implementations
- IDotNetClassFactory_Impl01
- interfaces
- IDotNetClassFactory
- testobjects
- implementations
- ITestCSharpObjectInterfacesImpl01
- interface
- ITestCSharpObjectInterfaces
- ManagedCOMLocalServer
- clients
- CPPClient01
- implementations
- ManagedCOMLocalServer_Impl01
- UsingStandardCOMInterop
- clients
- CPP
- CPPClient01
- implementations
- SimpleCOMObject_CSharpExeImpl
- SimpleCOMObject
- clients
- CPP
- CPPClient01
- VB
- VBClient01
- FormMain.frm
- MSSCCPRJ.SCC
- VBClient01.exe
- VBClient01.vbp
- VBClient01.vbw
- implementations
- C#
- SimpleCOMObject_CSharpImpl
- CPP
- SimpleCOMObject_CPPImpl
- interfaces
- SimpleCOMObject
|
// CPPClient01.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#import "SimpleCOMObject.tlb"
using namespace SimpleCOMObjectLib;
// Generic CreateInstance() templated function to help in generic object creation.
template <class SmartPtrClass>
bool CreateInstance(LPCTSTR lpszProgID, SmartPtrClass& spSmartPtrReceiver, DWORD dwClsContext = CLSCTX_ALL)
{
HRESULT hrRetTemp = S_OK;
_bstr_t bstProgID(lpszProgID);
CLSID clsid;
bool bRet = false;
hrRetTemp = CLSIDFromProgID
(
(LPCOLESTR)bstProgID, //Pointer to the ProgID
(LPCLSID)&clsid //Pointer to the CLSID
);
if (hrRetTemp == S_OK)
{
if (SUCCEEDED(spSmartPtrReceiver.CreateInstance(clsid, NULL, dwClsContext)))
{
bRet = true;
}
else
{
bRet = false;
}
}
return bRet;
}
int _tmain(int argc, _TCHAR* argv[])
{
::CoInitialize(NULL);
if (1)
{
// ISimpleCOMObjectPtr is a smart pointer class which will manage
// a pointer to the COM interface ISimpleCOMObject for us.
ISimpleCOMObjectPtr spISimpleCOMObject_CSharpExeImpl = NULL;
// We create an instance of an implementation of the ISimpleCOMObject interface
// as provided by the COM class whose CLSID is synonymous
// with the ProgID "SimpleCOMObject_CSharpExeImpl.SimpleCOMObject".
CreateInstance<ISimpleCOMObjectPtr>("SimpleCOMObject_CSharpExeImpl.SimpleCOMObject", spISimpleCOMObject_CSharpExeImpl, CLSCTX_INPROC_SERVER /* CLSCTX_LOCAL_SERVER */);
if (spISimpleCOMObject_CSharpExeImpl)
{
spISimpleCOMObject_CSharpExeImpl -> put_LongProperty(1000);
spISimpleCOMObject_CSharpExeImpl -> Method01(_bstr_t("C# Exe Implementation. The Long Property Value Is : "));
}
}
::CoUninitialize();
return 0;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
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.