COM线程模型 - MTA接口 (STA套间调用MTA对象)

本文探讨了COM线程模型中,单一线程公寓(STA)组件如何调用多线程公寓(MTA)接口。通过引用微软的技术支持文档和论坛讨论,深入解析这一过程中的关键概念和技术细节。
摘要由CSDN通过智能技术生成
那么如果在STA套间里面创建MTA对象,又如何?
看这段代码:
// TestCom.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <atlbase.h>
#include <atlcom.h>
#include "../MyCOM/MyCOM_i.h"
#include "../MyCOM/MyCOM_i.c"

#include <iostream>
#include <thread>


using namespace std;

void WorkThread()
{
    CoInitialize(0);

    WCHAR temp[100] = { 0 };
    swprintf_s(temp, L"thread tid: %d\n", ::GetCurrentThreadId());
    ::OutputDebugStringW(temp);

    {
        CComPtr<IMyRect> spRect;
        HRESULT hr = spRect.CoCreateInstance(CLSID_MyRect, NULL, CLSCTX_INPROC_SERVER);

        hr = spRect->Draw(CComBSTR(L"red"));
    }

    CoUninitialize();
}

int _tmain(int argc, _TCHAR* argv[])
{
	CoInitialize(0);

    WCHAR temp[100] = {0};
    swprintf_s(te
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值