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

비밀번호

댓글 작성자
 




... 181  182  183  184  185  186  187  188  189  190  191  192  193  194  [195]  ...
NoWriterDateCnt.TitleFile(s)
63정성태10/3/200422977.NET Framework: 14. Response.Cookies.Clear는 기존 설정된 Cookie 헤더를 삭제하는 것이 아닙니다.
62정성태10/3/200421955기타: 7. DB 트랜잭션에서 Lock이 걸릴 수 있는 전형적인 예.
61정성태10/3/200421503.NET Framework: 13. Main 메서드에 붙은 STAThread 의미
60정성태10/3/200420233.NET Framework: 12. IDispatch::GetIDsOfNames 역변환 메서드 작성 힌트 ( DISPID 로 메서드 이름 알아내는 것 )
58정성태10/3/200423339.NET Framework: 11. HttpContext의 간략이해
56정성태10/3/200419855.NET Framework: 10. [.NET 리모팅] 원격개체를 호출한 클라이언트의 연결이 유효한지 판단하는 방법.
55정성태10/3/200420614COM 개체 관련: 11. 내가 생각해 보는 COM의 현재 위치
54정성태8/30/200426279VC++: 10. 내가 생각해 보는 MFC OCX와 ATL DLL에 선택 기준
53정성태11/20/200525620VC++: 9. CFtpFileFind/FtpFileFind가 일부 Unix FTP 서버에서 목록을 제대로 못 가져오는 문제
184정성태11/23/200519284    답변글 VC++: 9.1. FTP 관련 토픽파일 다운로드1
51정성태6/24/200424194VC++: 8. BSTR 메모리 할당 및 해제(MSDN Library 발췌) [1]
50정성태6/16/200417462기타: 6. 1차 데스크톱 컴퓨터 사양
49정성태6/16/200417935기타: 5. 53만 원대 Second PC 마련. ^^
48정성태3/2/200419835.NET Framework: 9. 윈도우즈 발전사를 모아 둔 사이트. [1]
47정성태11/14/200518303VS.NET IDE: 7. 한글 OS에서 Internet Explorer 6.0 with SP1의 UI 언어 바꾸는 방법
45정성태1/26/200417678기타: 4. MCAD 시험
44정성태1/26/200418499VS.NET IDE: 6. 터미널 서비스 포트 변경 ( 서버 및 클라이언트 )
46정성태1/26/200423599    답변글 VS.NET IDE: 6.1. Windows 2003 터미널 서비스 라이센스 서버 없이 접속
114정성태11/14/200515028    답변글 VS.NET IDE: 6.2. [터미널 서버 라이센스] : 활성화 시 오류
43정성태12/23/200318228기타: 3. XP/2003 개인 방화벽 설정파일 다운로드1
40정성태7/23/200321701COM 개체 관련: 10. IE BHO 개체를 개발할 때, 인터넷 익스플로러가 아닌 탐색기에서 활성화 되는 문제 해결 [1]
41김성현7/24/200320514    답변글 COM 개체 관련: 10.1. [답변]: IE BHO 개체를 개발할 때, 인터넷 익스플로러가 아닌 탐색기에서 활성화 되는 문제 해결
42정성태7/29/200318400        답변글 COM 개체 관련: 10.2. feedback 을 받기 위해서 답변 기능을 가능하게 해두었습니다.
39정성태7/17/200324153VS.NET IDE: 5. 원격 제어 3가지 방법
38정성태7/17/200320721.NET Framework: 8. IIS 서버 재설치와 ASP.NET 서비스의 문제점
36정성태7/17/200321414.NET Framework: 7. 시행착오 - WebService 참조 추가 오류
... 181  182  183  184  185  186  187  188  189  190  191  192  193  194  [195]  ...