VC에서 원격 데이터 객체 호출하는 방법 DarkKaiser, 2008년 4월 11일2023년 9월 5일 IDispatch* CreateConnection(LPCTSTR strAddr) { #ifdef UNICODE LPTSTR strAddress = strAddr; #else size_t sl = strlen(strAddr); LPWSTR strAddress = new WCHAR[sl+1]; strAddress[sl] = 0; mbstowcs(strAddress, strAddr, sl); #endif IDispatch* pDispatch = NULL; bool ok = false; RDS::IDataspacePtr pDS; if (SUCCEEDED(pDS.CreateInstance(OLESTR("RDS.DataSpace")))) { _variant_t Result; try { Result = pDS->CreateObject(_bstr_t("Component.bizCOM"), _bstr_t(strAddress)); HRESULT hr = Result.pdispVal->QueryInterface(_uuidof(IDispatch), (LPVOID*) &pDispatch); WriteLog(_T("CreateConnection :: HR = %x, IDispatch = %p"), hr, pDispatch); } catch(_com_error& e) { WriteLog(_T("CreateConnection :: exception. [%s]"), e.ErrorMessage()); } } #ifndef _UNICODE delete strAddress; #endif return pDispatch; } virtual bool WINAPI Test() { bool ok = false; try { IDispatch *pConn = CreateConnection(m_strTarget); if(pConn != NULL) { LPOLESTR strFuncName = L"GetSqlLog2"; DISPID dispid = 0; HRESULT hr = pConn->GetIDsOfNames(IID_NULL, &strFuncName, 1, LOCALE_SYSTEM_DEFAULT, &dispid); WriteLog(_T("Test :: DISPID = %u. hr = %x"), dispid, hr); if(SUCCEEDED(hr)) { BSTR tmp = NULL; hr = _com_dispatch_method( pConn, dispid, DISPATCH_METHOD, VT_BSTR, &tmp, NULL); ok = SUCCEEDED(hr); WriteLog(_T("Test :: execution result is [%x]"), hr); } pConn->Release(); } } catch(_com_error e) { WriteLog(_T("Test :: exception handled. [%s:%x]"), e.ErrorMessage(), e.Error()); } return ok; } C/C++/VC++ COMRDS