Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일


COM 개체로 인해 IE 7 비스타 버전이 종료될 때 오류 화면이 뜬다면?

My Toolbar or BHO is Causing IE7 on Vista to Crash on Close. Help!
; https://docs.microsoft.com/en-us/archive/blogs/tonyschr/my-toolbar-or-bho-is-causing-ie7-on-vista-to-crash-on-close-help

코딩에서도, "형식 안정성"을 중요하게 여기는 것처럼, 점차로 마이크로소프트의 전반적인 제품군에서 "오류임에도 불구하고 덮어주던 방식"을 없애는 방향으로 가고 있는 것 같습니다. 위의 기사에서 언급하는 문제도 그와 같은 식이라고 볼 수 있겠지요.

CoInitialize() / CoUninitialize()의 쌍이 맞지 않는 경우에 IE 6까지는 그러한 실수를 감안하여 문제가 없도록 되어 있었는데, IE 7부터는 문제가 발생하게 되었다고 합니다. 만약, 여러분들의 프로그램에서 - 사실 별도의 스레드를 만들지 않는 한 CoInitialize() / CoUninitialize()를 호출할 일은 거의 없지만, 만약 사용하고 있다면 반드시 그 부분에 대한 호출 쌍이 맞는지 확인하셔야 할 것입니다.

그러면서, "IInitializeSpy" 인터페이스를 소개해 주고 있습니다. 어허... 제가 그동안 많이 무심했습니다. 이런 인터페이스가 있었는 줄 처음 알았으니까요. (Windows XP SP1부터 지원되었다고 합니다.) 이 인터페이스는 CoInitialize / CoUninitialize 메서드들이 호출될 때마다 Pre/Post 콜백 함수를 불려지는 것을 목적으로 정의된 것입니다.

테스트 삼아서 간단한 예제를 한번 작성해 보았습니다. (참고로, 위의 기사를 쓴 사람은 절대로 ActiveX 개발자들이 자신들의 CoInitialize() / CoUninitialize() 호출 쌍을 보정하기 위해 이 인터페이스를 구현하지 말라고 당부하고 있습니다.)

참고로, 아래의 예제에 대해 컴파일 가능한 VC++ 8 프로젝트파일은 첨부파일에 넣어두었습니다.

#include "stdafx.h"
#include <windows.h>
#include <objbase.h>
#include <objidl.h>

#pragma comment(lib, "ole32.lib")

class CInitializeSpy : public IInitializeSpy
{
public:
	CInitializeSpy()
	{
		dwCount = 0;
	}

	STDMETHOD(PreInitialize)(DWORD dwCoInit,DWORD dwCurThreadAptRefs)
	{
		::OutputDebugStr(L"PreInitialize\r\n");
		return S_OK;
	}

	STDMETHOD(PostInitialize)(HRESULT hrCoInit,DWORD dwCoInit,DWORD dwNewThreadAptRefs)
	{
		::OutputDebugStr(L"PostInitialize\r\n");
		return S_OK;
	}

	STDMETHOD(PreUninitialize)(DWORD dwCurThreadAptRefs)
	{
		::OutputDebugStr(L"PreUninitialize\r\n");
		return S_OK;
	}

	STDMETHOD(PostUninitialize)(DWORD dwNewThreadAptRefs)
	{
		::OutputDebugStr(L"PostUninitialize\r\n");
		return S_OK;
	}

	STDMETHOD(QueryInterface)(REFIID riid, void **ppvObject)
	{
		bool qied = false;

		if ( riid == IID_IUnknown)
		{
			*ppvObject = this;
			qied = true;
		}

		if ( riid == IID_IInitializeSpy)
		{
			*ppvObject = this;
			qied = true;
		}

		if ( qied == true )
		{
			dwCount ++;
			return S_OK;
		}

		return E_NOINTERFACE;
	}

	virtual ULONG STDMETHODCALLTYPE AddRef( void)
	{
		dwCount ++;
		return dwCount;
	}

	virtual ULONG STDMETHODCALLTYPE Release( void)
	{
		dwCount --;

		if ( dwCount == 0 )
		{
			delete this;
		}

		return dwCount;
	}

	DWORD dwCount;
};

int _tmain(int argc, _TCHAR* argv[])
{
	CInitializeSpy *pSpy = new CInitializeSpy();
	ULARGE_INTEGER ulCookie;

	CoRegisterInitializeSpy(pSpy, &ulCookie);

	CoInitialize(NULL);
	CoUninitialize();

	CoRevokeInitializeSpy(ulCookie);
	return 0;
}




[이 토픽에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 7/9/2021]

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

비밀번호

댓글 작성자
 




... 76  77  78  79  80  81  82  83  84  85  86  [87]  88  89  90  ...
NoWriterDateCnt.TitleFile(s)
11795정성태12/19/201822373Windows: 154. PowerShell - Zone 별로 DNS 레코드 유형 정보 조회 [1]
11794정성태12/16/201818295오류 유형: 508. Get-AzureWebsite : Request to a downlevel service failed.
11793정성태12/16/201821131개발 환경 구성: 423. NuGet 패키지 제작 - Native와 Managed DLL을 분리하는 방법 [1]
11792정성태12/11/201820016Graphics: 34. .NET으로 구현하는 OpenGL (11) - Per-Pixel Lighting파일 다운로드1
11791정성태12/11/201820184VS.NET IDE: 130. C/C++ 프로젝트의 시작 프로그램으로 .NET Core EXE를 지정하는 경우 닷넷 디버깅이 안 되는 문제 [1]
11790정성태12/11/201819105오류 유형: 507. Could not save daemon configuration to C:\ProgramData\Docker\config\daemon.json: Access to the path 'C:\ProgramData\Docker\config' is denied.
11789정성태12/10/201833131Windows: 153. C# - USB 장치의 연결 및 해제 알림을 위한 WM_DEVICECHANGE 메시지 처리 [2]파일 다운로드2
11788정성태12/4/201818965오류 유형: 506. SqlClient - Value was either too large or too small for an Int32.Couldn't store <2151292191> in ... Column
11787정성태11/29/201823130Graphics: 33. .NET으로 구현하는 OpenGL (9), (10) - OBJ File Format, Loading 3D Models파일 다운로드1
11786정성태11/29/201820099오류 유형: 505. OpenGL.NET 예제 실행 시 "Managed Debugging Assistant 'CallbackOnCollectedDelegate'" 예외 발생
11785정성태11/21/201822052디버깅 기술: 120. windbg 분석 사례 - ODP.NET 사용 시 Finalizer에서 System.AccessViolationException 예외 발생으로 인한 비정상 종료
11784정성태11/18/201821175Graphics: 32. .NET으로 구현하는 OpenGL (7), (8) - Matrices and Uniform Variables, Model, View & Projection Matrices파일 다운로드1
11783정성태11/18/201819964오류 유형: 504. 윈도우 환경에서 docker가 설치된 컴퓨터 간의 ping IP 주소 풀이 오류
11782정성태11/18/201818422Windows: 152. 윈도우 10에서 사라진 "Adapters and Bindings" 네트워크 우선순위 조정 기능 - 두 번째 이야기
11781정성태11/17/201822361개발 환경 구성: 422. SFML.NET 라이브러리 설정 방법 [1]파일 다운로드1
11780정성태11/17/201823101오류 유형: 503. vcpkg install bzip2 빌드 에러 - "Error: Building package bzip2:x86-windows failed with: BUILD_FAILED"
11779정성태11/17/201823915개발 환경 구성: 421. vcpkg 업데이트 [1]
11778정성태11/14/201820925.NET Framework: 803. UWP 앱에서 한 컴퓨터(localhost, 127.0.0.1) 내에서의 소켓 연결
11777정성태11/13/201821874오류 유형: 502. Your project does not reference "..." framework. Add a reference to "..." in the "TargetFrameworks" property of your project file and then re-run NuGet restore.
11776정성태11/13/201820111.NET Framework: 802. Windows에 로그인한 계정이 마이크로소프트의 계정인지, 로컬 계정인지 알아내는 방법
11775정성태11/13/201821216Graphics: 31. .NET으로 구현하는 OpenGL (6) - Texturing파일 다운로드1
11774정성태11/8/201820216Graphics: 30. .NET으로 구현하는 OpenGL (4), (5) - Shader파일 다운로드1
11773정성태11/7/201819970Graphics: 29. .NET으로 구현하는 OpenGL (3) - Index Buffer파일 다운로드1
11772정성태11/6/201821501Graphics: 28. .NET으로 구현하는 OpenGL (2) - VAO, VBO파일 다운로드1
11771정성태11/5/201820562사물인터넷: 56. Audio Jack 커넥터의 IR 적외선 송신기 - 두 번째 이야기 [1]
11770정성태11/5/201829627Graphics: 27. .NET으로 구현하는 OpenGL (1) - OpenGL.Net 라이브러리 [3]파일 다운로드1
... 76  77  78  79  80  81  82  83  84  85  86  [87]  88  89  90  ...