📄 testcreditobject.cpp
字号:
// TestCreditObject.cpp
#include "stdafx.h"
#import "..\CreditServer\CreditServer\Debug\CreditServer.tlb" \
no_namespace named_guids
void __stdcall AnotherThread(IStream* pIS)
{
// STA second thread
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
try
{
ICreditVerificationPtr p;
hr = CoGetInterfaceAndReleaseStream(pIS,
IID_ICreditVerification, (void**)&p);
if (FAILED(hr))
_com_issue_error(hr);
p->SetCardType("Visa");
if (p->VerifyCardNumber(3) == S_OK)
MessageBox(0, "AnotherThread: Card Verified", "OK", 0);
else
MessageBox(0, "AnotherThread: Card Rejected", 0, 0);
}
catch (_com_error &e)
{
cout << "AnotherThread: " << e.ErrorMessage() << "\n";
}
CoUninitialize();
}
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE tH;
IStream* pIS;
CoInitializeEx(NULL, COINIT_MULTITHREADED);
try
{
ICreditVerificationPtr p(CLSID_CreditVerification);
HRESULT hr = CoMarshalInterThreadInterfaceInStream(
IID_ICreditVerification, p, &pIS);
if (FAILED(hr))
_com_issue_error(hr);
DWORD tID;
tH = CreateThread(0, 0,
(LPTHREAD_START_ROUTINE)AnotherThread, (void*)pIS, 0, &tID);
p->SetCardType("MasterCard");
if (p->VerifyCardNumber(1234) == S_OK)
MessageBox(0, "Main Thread: Card Verified", "OK", 0);
else
MessageBox(0, "Main Thread: Card Rejected", 0, 0);
}
catch(_com_error& e)
{
MessageBox(0, e.ErrorMessage(), 0, 0);
}
WaitForSingleObject(tH, INFINITE);
CoUninitialize();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -