사용자 도구

사이트 도구


사이드바

카테고리

language:cpp:managedcpp-ref

Managed Extensions For Cpp

Cpp하고 호환성을 위해서 만든 줄 알았는데, 아닌가 보네? 바로 쓸 수 있는 건줄 알았는데, 아니라서 매뉴얼을 읽어보기로 함. 앞으로 시간이 더 걸릴 듯.

그냥 C#을 쓰는 것과 뭐가 다른지 모르겠음.

  • Native : 이전에 써오던 그 Cpp
  • Managed : Extented Managed Cpp (문법이 다름)
  • Mixed : Native + Managed –> 그냥 되는 것이 아니라,
    • 코딩 방법도 다르고
    • 데이터 교환은 마샬링이라는 방법을 통해서 처리한다.
  • 과연 이 Mixed 모드가 나중에도 남아 있게 될지 다소 의문스럽다.

다수레퍼런스

컴파일 옵션

/clr Mixed mode 를 지원하는
/clr:pure Managed 만 사용되는 모드

C++/CLI with ATL

프로젝트 구성 사항 변경 (To compile an ATL executable by using /clr)

변경 순서

  1. In Solution Explorer, right-click the project and then click Properties.
  2. In the Project Properties dialog box, expand the node next to Configuration Properties and select General.
    In the right pane, under Project Defaults,
    set Common Language Runtime support to Common Language Runtime Support (/clr).
  3. Under Configuration Properties, expand the node next to C/Cpp and select General.
    Make sure that Debug Information Format is set to Program Database /Zi (not /ZI).
  4. Select the Code Generation node.
    Set Enable Minimal Rebuild to No (/Gm-).
    Also set Basic Runtime Checks to Default.
  5. Under Configuration Properties, select C/Cpp and then Code Generation. Make sure that Runtime Library is set to either Multi-threaded Debug DLL (/MDd) or Multi-threaded DLL (/MD).
  6. For every MIDL-generated file (C files), right-click the file in Solution Explorer and then click Properties.
    Under Configuration Properties, expand the node next to C/Cpp and select General.
    Set Compile with Common Language Runtime support to No Common Language Runtime support.

그외 native code 작성시 주의사항

  1. 헤더와 소스는 분리해야 함, 헤더 내부에 코드를 넣으면 중복 선언으로 컴파일 에러 발생
  2. _ATL_MIXED 추가
    1. stdafx.h 나 ATL 이 사용되는 곳에

디버깅 중에 에러 뜨는 경우,

  __DllMainCRTStartup@12 를 "프로젝트프로퍼티 ⇒ 링커 ⇒ 입력"의 강제 기호 참조에 추가
  it is needed to set __DllMainCRTStartup@12 in the forced reference section

와 같이 하면 잘 실행 됨.

메인폼 얻기

현재 활성화된 폼을 얻기

System.Windows.Forms.Form.ActiveForm

Form.ActiveForm 속성

  • 주의사항 : 쓰레드가 다른 경우 ActiveForm은 null이 되게 됨

폼의 컨트롤을 사용하기

이유

  • 컨트롤 메소드의 대부분은 그 컨트롤이 만들어진 쓰레드에서만 호출 될 수 있다.

검색용 관련 키워드

  • InvokeRequire
  • Invoke
  • BeginInvoke
  • EndInvoke
  • CreateGraphics (?)

괜히 삽질했네, 레퍼런스가 있습니다.

language/cpp/managedcpp-ref.txt · 마지막으로 수정됨: 2022/12/07 22:30 저자 kieuns