Microsoft MVP성태의 닷넷 이야기
글쓴 사람
light
홈페이지
첨부 파일
 
부모글 보이기/감추기

현재 생성된 부분의 Thread 와 사용하는 스레드가 틀리므로, 어드레스 값은 같고 있지만, 실제적으로 호출이 안됨...

그러므로 , 처음에 생성한 com object을 global 쪽에 놓고 사용함.    


//----------------------------------------------------------------------------------------
#ifndef _RCCOMMARSHAL_H_
#define _RCCOMMARSHAL_H_
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
#include <vector>
using namespace std;
#include <windows.h>
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
class CRCComMarshal
{
    typedef struct
    {        
        IID m_iid;
        DWORD m_dwCookie;
    }SIIDCOOKIE;

public:
    CRCComMarshal();
    virtual ~CRCComMarshal();
    static CRCComMarshal * Instance();
    bool Register(IUnknown *pUnk, REFIID riid);
    bool UnRegister(REFIID riid);
    bool GetInterfacePointer(REFIID riid, void **ppInterface, int nInd=1);
protected:
private:
    bool Init();
    bool CheckIfAlreadyRegistered(REFIID riid);

    LPGLOBALINTERFACETABLE m_pGIT;
    typedef vector<SIIDCOOKIE*> COOKIEVEC;
    COOKIEVEC m_vecCookies;
    CRITICAL_SECTION m_CS;
};
//----------------------------------------------------------------------------------------
#endif //_RCCOMMARSHAL_H_
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------



//----------------------------------------------------------------------------------------
// Contructor
/////////////////
CRCComMarshal::CRCComMarshal()
{
    m_pGIT = NULL;
    InitializeCriticalSection(&m_CS);
    Init();
}
//----------------------------------------------------------------------------------------

///////////////////////////////////////////////////////////////
CRCComMarshal::~CRCComMarshal()
{
    int nSize = m_vecCookies.size();
    if (nSize > 0)
    {
        SIIDCOOKIE *psiid = NULL;
        HRESULT hr = S_OK;
        for (int nIndex=0 ; nIndex<nSize ; nIndex++)
        {
            psiid = NULL;
            psiid = m_vecCookies[nIndex];
            if (NULL != psiid)
            {
                if (NULL != psiid)
                {
                    hr = S_OK;
                    hr = m_pGIT->RevokeInterfaceFromGlobal(psiid->m_dwCookie);
                }
                delete psiid;
            }
        }

        m_vecCookies.clear();
    }
}
//----------------------------------------------------------------------------------------

////////////////////////////////////////////////////////////////////
bool CRCComMarshal::Init()
{
    bool bRet = true;
    
    HRESULT hr = CoCreateInstance(CLSID_StdGlobalInterfaceTable, NULL, CLSCTX_SERVER,
        IID_IGlobalInterfaceTable, (void**)&m_pGIT);

    if (FAILED(hr))
        bRet = false;

    return bRet;
}


////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------------------
bool CRCComMarshal::Register(IUnknown *pUnk, REFIID riid)
{
    CRCCriticalSectionLock Lock(&m_CS);

    bool bRet = true;
    HRESULT hr = S_OK;
    DWORD dwCookie=0;


    //////////////////////////////////////////
//    if (true == CheckIfAlreadyRegistered(riid))
//    {
//        return true;
//    }
    

    ///////////////////////////////////////////////////////////////
    hr = m_pGIT->RegisterInterfaceInGlobal(pUnk, riid, &dwCookie);

    // Exit if register not successfull
    //////////////////////////////////////
    if ((FAILED(hr)) || (0 == dwCookie))
    {
        bRet = false;
        return bRet;
    }

    // Insert the cookie into the vector
    ////////////////////////////////////
    SIIDCOOKIE *psiid = new SIIDCOOKIE;
    psiid->m_iid = riid;
    psiid->m_dwCookie = dwCookie;
    m_vecCookies.push_back(psiid);


    return bRet;
}

bool CRCComMarshal::GetInterfacePointer(REFIID riid, void **ppInterface, int nInd)
{
    CRCCriticalSectionLock Lock(&m_CS);

    bool bRet = true;
    HRESULT hr = S_OK;
    DWORD dwCookie=0;

    if (NULL == ppInterface)
    {
        bRet = false;
        return bRet;
    }

    *ppInterface = NULL;

    // Get the interface's Cookie from the vector
    /////////////////////////////////////////////
    int nSize = m_vecCookies.size();
    SIIDCOOKIE *psiid = NULL;
    bool bFound = false;
    int nCount=nInd;
    if (nCount < 1)
        nCount = 1;
    for (int nIndex=0 ; nIndex<nSize ; nIndex++)
    {
        psiid = NULL;
        psiid = m_vecCookies[nIndex];
        if (NULL != psiid)
        {
            if (riid == psiid->m_iid)
            {
                nCount--;
                if (0 == nCount)
                {
                    bFound = true;
                    dwCookie = psiid->m_dwCookie;
                    break;
                }
            }
        }

    }

    if (true != bFound)
    {
        return false;
    }

    // Retrieve the interface pointer from Glabal interface table
    ///////////////////////////////////////////////////////////////
    hr = m_pGIT->GetInterfaceFromGlobal(dwCookie, riid, ppInterface);
    if ((FAILED(hr)) || (NULL == *ppInterface))
    {
        bRet = false;
        return bRet;
    }

    return bRet;
}

/////////////////////////////////////////////////////////////////////
bool CRCComMarshal::CheckIfAlreadyRegistered(REFIID riid)
{
    int nSize = m_vecCookies.size();
    bool bFound = false;
    SIIDCOOKIE *psiid = NULL;
    for (int nIndex=0 ; nIndex<nSize ; nIndex++)
    {
        psiid = NULL;
        psiid = m_vecCookies[nIndex];
        if (NULL != psiid)
        {
            if (riid == psiid->m_iid)
            {
                bFound = true;
                break;
            }
        }

    }

    return bFound;
}
//----------------------------------------------------------------------------------------

////////////////////////////////////////////////////////////////////
bool CRCComMarshal::UnRegister(REFIID riid)
{
    CRCCriticalSectionLock Lock(&m_CS);

    int nSize = m_vecCookies.size();
    bool bFound = false;
    SIIDCOOKIE *psiid = NULL;
    for (int nIndex=0 ; nIndex<nSize ; nIndex++)
    {
        psiid = NULL;
        psiid = m_vecCookies[nIndex];
        if (NULL != psiid)
        {
            if (riid == psiid->m_iid)
            {
                bFound = true;
                break;
            }
        }
    }

    HRESULT hr = S_OK;
    if ((NULL != psiid) && (true == bFound))
    {
        hr = m_pGIT->RevokeInterfaceFromGlobal(psiid->m_dwCookie);
        m_vecCookies.erase(m_vecCookies.begin() + nIndex);
        if (FAILED(hr))
        {
            return false;
        }
    }

    return true;
}
저는 이렇게 사용했습니다...

전에 SSL질문을 했는데, 잘알려줘서, 제가 아는 범위로 답변했습니다.
그댄 아직 해결 못했어요...ㅠㅠ.환경설정을 잘 못하겠네요








[최초 등록일: ]
[최종 수정일: 10/30/2006]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... [16]  17  18  19  20  21  22  23  24  25  26  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
13250정성태2/8/20236640오류 유형: 843. System.InvalidOperationException - Unable to configure HTTPS endpoint
13249정성태2/7/20235471오류 유형: 842. 리눅스 - You must wait longer to change your password
13248정성태2/7/20234381오류 유형: 841. 리눅스 - [사용자 계정] is not in the sudoers file. This incident will be reported.
13247정성태2/7/20235276VS.NET IDE: 180. Visual Studio - 닷넷 소스 코드 디버깅 중 "Decompile source code"가 동작하는 않는 문제
13246정성태2/6/20234471개발 환경 구성: 664. Hyper-V에 설치한 리눅스 VM의 VHD 크기 늘리는 방법 - 두 번째 이야기
13245정성태2/6/20235081.NET Framework: 2093. C# - PEM 파일을 이용한 RSA 개인키/공개키 설정 방법파일 다운로드1
13244정성태2/5/20234465VS.NET IDE: 179. Visual Studio - External Tools에 Shell 내장 명령어 등록
13243정성태2/5/20235290디버깅 기술: 190. windbg - Win32 API 호출 시점에 BP 거는 방법 [1]
13242정성태2/4/20234740디버깅 기술: 189. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.UnauthorizedAccessException
13241정성태2/3/20234133디버깅 기술: 188. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.IO.FileNotFoundException
13240정성태2/1/20234295디버깅 기술: 187. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.Web.HttpException
13239정성태2/1/20233983디버깅 기술: 186. C# - CacheDependency의 숨겨진 예외 - System.Web.HttpException
13238정성태1/31/20236151.NET Framework: 2092. IIS 웹 사이트를 TLS 1.2 또는 TLS 1.3 프로토콜로만 운영하는 방법
13237정성태1/30/20235849.NET Framework: 2091. C# - 웹 사이트가 어떤 버전의 TLS/SSL을 지원하는지 확인하는 방법
13236정성태1/29/20235270개발 환경 구성: 663. openssl을 이용해 인트라넷 IIS 사이트의 SSL 인증서 생성
13235정성태1/29/20234955개발 환경 구성: 662. openssl - 윈도우 환경의 명령행에서 SAN 적용하는 방법
13234정성태1/28/20236068개발 환경 구성: 661. dnSpy를 이용해 소스 코드가 없는 .NET 어셈블리의 코드를 변경하는 방법 [1]
13233정성태1/28/20237423오류 유형: 840. C# - WebClient로 https 호출 시 "The request was aborted: Could not create SSL/TLS secure channel" 예외 발생
13232정성태1/27/20235035스크립트: 43. uwsgi의 --processes와 --threads 옵션
13231정성태1/27/20234086오류 유형: 839. python - TypeError: '...' object is not callable
13230정성태1/26/20234491개발 환경 구성: 660. WSL 2 내부로부터 호스트 측의 네트워크로 UDP 데이터가 1개의 패킷으로만 제한되는 문제
13229정성태1/25/20235531.NET Framework: 2090. C# - UDP Datagram의 최대 크기
13228정성태1/24/20235661.NET Framework: 2089. C# - WMI 논리 디스크가 속한 물리 디스크의 정보를 얻는 방법 [2]파일 다운로드1
13227정성태1/23/20235267개발 환경 구성: 659. Windows - IP MTU 값을 바꿀 수 있을까요? [1]
13226정성태1/23/20234965.NET Framework: 2088. .NET 5부터 지원하는 GetRawSocketOption 사용 시 주의할 점
13225정성태1/21/20234137개발 환경 구성: 658. Windows에서 실행 중인 소켓 서버를 다른 PC 또는 WSL에서 접속할 수 없는 경우
... [16]  17  18  19  20  21  22  23  24  25  26  27  28  29  30  ...