- ccomthread_src.zip
- LegacyCOMObject1
- Shared
- SimpleCOMObject1
- SimpleCOMObject2
- Test Programs
- VBTest
- VCTests
- DemonstrateDefaultSTA
- VCTest01
- main.cpp
- SimpleCOMObject2.tlh
- SimpleCOMObject2.tli
- VCTest01.dsp
- VCTest01.dsw
- VCTest02
- main.cpp
- SimpleCOMObject2.tlh
- SimpleCOMObject2.tli
- VCTest02.dsp
- VCTest02.dsw
- DemonstrateExeServerSTA
- Client
- VCTest01
- Implementation
- ExeServerImpl
- Interface
- ExeServerInterfaces
- DemonstrateLegacySTA
- VCTest01
- LegacyCOMObject1.tlh
- LegacyCOMObject1.tli
- main.cpp
- VCTest01.dsp
- VCTest01.dsw
- VCTest02
- DemonstrateNoMessageLoop
- VCTest01
- main.cpp
- SimpleCOMObject2.tlh
- SimpleCOMObject2.tli
- VCTest01.dsp
- VCTest01.dsw
- DemonstrateSTA
- VCTest01
- main.cpp
- SimpleCOMObject2.tlh
- SimpleCOMObject2.tli
- VCTest01.dsp
- VCTest01.dsw
|
#define _WIN32_WINNT 0x0400
#include <windows.h>
#include <stdio.h>
#import "..\..\..\..\SimpleCOMObject2\Debug\SimpleCOMObject2.dll"
using namespace SIMPLECOMOBJECT2Lib;
// Simple function that displays the current thread ID.
void DisplayCurrentThreadId()
{
TCHAR szMessage[256];
sprintf (szMessage, "Thread ID : 0x%X", GetCurrentThreadId());
::MessageBox(NULL, szMessage, "TestMethod1()", MB_OK);
}
// If we enter an STA (using COINIT_APARTMENTTHREADED),
// all STA objects will live in the same STA as main()'s thread.
//
// If we enter non-STA (using COINIT_MULTITHREADED), STA objects
// created in main()'s thread will live in default STA.
int main()
{
//::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); // Use COINIT_APARTMENTTHREADED and the TestMethod1() will run on the same thread as main().
::CoInitializeEx(NULL, COINIT_MULTITHREADED); // Use COINIT_MULTITHREADED and TestMethod1() will run on another thread.
DisplayCurrentThreadId();
if (1)
{
ISimpleCOMObject2Ptr spISimpleCOMObject2;
// If a default STA is to be created and used, it will be created
// right after spISimpleCOMObject2 (an STA object) is created.
spISimpleCOMObject2.CreateInstance(__uuidof(SimpleCOMObject2));
spISimpleCOMObject2 -> TestMethod1(); // This will message box display the thread id of the thread in which TestMethod1() is running.
}
::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.