Skip to content
DarkKaiser의 블로그
DarkKaiser의 블로그
  • 개발 관련 자료(노션)
  • Raspberry Pi(노션)
  • WD My Cloud(노션)
  • GitHub
DarkKaiser의 블로그

VC에서 원격 데이터 객체 호출하는 방법

DarkKaiser, 2008년 4월 11일2023년 9월 5일
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
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; }
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

글 내비게이션

Previous post
Next post

답글 남기기 응답 취소

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

최신 글

  • AssertJ 소개testCompile ‘org.assertj:assertj-core:3.6.2’ 2017년 9월 14일
  • 자주 사용되는 Lombok 어노테이션 2017년 9월 14일
  • 유니코드 #3 2017년 9월 14일
  • 유니코드 #2 2017년 9월 14일
  • 유니코드 #1 2017년 9월 14일

최신 댓글

    카테고리

    • 개인 자료 (1)
      • 일기 (1)
    • 주절주절 (7)
    • 프로그래밍 갤러리 (16)
    • 프로그래밍 언어 (186)
      • Java (29)
      • C/C++/VC++ (114)
      • C# (11)
      • Visual Basic (6)
      • 안드로이드 (9)
      • Objective-C (5)
      • JavaScript (4)
      • JSP/Servlet (2)
      • Python (4)
      • 어셈블러 (1)
    • 개발++ (44)
      • Book (11)
        • Joel On Software (10)
      • 프로젝트 관리 (6)
      • Maven (1)
      • 디버깅 (1)
      • DirectX (1)
      • Silverlight (1)
      • RESTful (1)
      • Hacking (1)
      • WDM (4)
      • VoIP (5)
      • 기타 (1)
    • 개발 도구 (15)
      • eclipse (14)
      • Sublime Text (1)
    • 네트워크 (7)
    • 설치 및 배포 (7)
      • InstallShield (2)
      • NSIS (4)
    • 버전 관리 (9)
      • Git (2)
      • CVS (2)
      • Subversion (5)
    • 데이터베이스 (7)
      • Oracle (3)
      • Sybase (2)
      • MS-SQL (2)
    • 단위테스트 (3)
      • JUnit (1)
      • NUnit (2)
    • 버그추적시스템 (2)
      • mantis (2)
    • 운영체제 (7)
      • Windows (5)
      • 리눅스 (2)
    • WAS (3)
      • WebLogic (3)
    • 디자인패턴 (1)
    • 디지털 이미지 프로세싱 (16)

    태그

    Assert() AutoExp.dat CppUnit CVS cvsnt Detours Generic Git ignore파일 Isolation level LogCat new OSI OSI 7 layer pragma RunInstaller Runnable session setPoperty startWebLogic.cmd std::auto_ptr STL STLPort synchronized TAB TCP/IP Thread useBean 날짜 디버깅 마스크 버그트래킹시스템 설치프로젝트 성능 시간 주석 캡쳐 탭 트랜젝션 트리 픽셀 형변환 형식 후킹 히스토그램

    메타

    • 로그인
    • 엔트리 피드
    • 댓글 피드
    • WordPress.org
    ©2025 DarkKaiser의 블로그 | WordPress Theme by SuperbThemes
    DarkKaiser의 블로그
    DarkKaiser의 블로그
    • 개발 관련 자료(노션)
    • Raspberry Pi(노션)
    • WD My Cloud(노션)
    • GitHub