출처: https://msdn.microsoft.com/ko-kr/library/605a12zt(v=vs.120).aspx



Visual Studio 2013 대상


How to: Debug from a DLL Project


To specify the calling application in a C++ project

  1. In Solution Explorer, select the DLL project.

  2. On the View menu, choose Property Pages.

  3. In the ProjectProperty Pages window, in the Configuration drop-down list, choose Debug.

  4. Open the Configuration Properties folder, and select the Debugging category.

  5. In the Debugger to launch list, choose Local Windows Debugger or Remote Windows Debugger.

  6. In the Command or Remote Command box, click the drop-down arrow, and select Browse from the list to locate the application.Alternatively, type the path and name of the application.

  7. Type any necessary program arguments in the Command Arguments box.

To specify the calling application in a C# or Visual Basic project

  1. In Solution Explorer, select the DLL project.

  2. On the View menu, choose Property Pages.

  3. In the ProjectProperty Pages window, in the Configuration drop-down list, choose Debug.

  4. Click the Debug tab.

  5. You can start the application by either doing the following:

    1. Set the Start Action to Start external program.

    2. In the Start external program box, click the ellipsis button to browse for the application.

    3. Enter any necessary program arguments in the Command Line Arguments box.

  6. Or, you can invoke an application at a URL. (You might want to do this if you are debugging a managed DLL used by a local ASP.NET application.)

    1. Under Start Action, select the Start browser in URL: radio button.

    2. In the adjoining text box, type the URL.

To start debugging from the DLL project

  1. In Solution Explorer, select the DLL project.

  2. Set breakpoints as needed.

  3. Enter the name and location of the calling application in the ProjectProperty Pages dialog box or window. If the application is a console application, fill in the command line arguments, if it is necessary.


Posted by 세모아
,

출처: http://sjc333.egloos.com/3131382



c++ dll (/clr) 을 c#에서 dllimport 하고 디버그(debug) 하기

제목이 좀 어렵네요.
그냥 이쪽 전공에서나 필요한 지식이고, 귀찮으니 최대한 요점만 짧게 로그 남기듯이 적습니다.
보통은 이런 뻔한 시나리오는 안적는데 vs2013의 황당한 버그 비슷한 것이 저를 괴롭혀서 2시간 가량 낭비하는 바람에 
저와 같은 피해자(?)가 없도록 글을 남기는 것입니다. ㅎㅎ


1. C++ dll을 만든다. 이때 clr 옵션을 건다. 자세한건 구글링...
  한줄만 더 적자면 CLR은 managed가 아니다.

2. C# 어플리케이션을 만들고 1에서 만든 dll을 .cs 소스코드 안에서 직접 import. 하고 작동되는지 확인한다.
  ex ) [DllImport("../bin/test.dll")]

이 글을 보는 사람이라면 사실 1과 2는 이미 되어있는 상태일 것이라고 가정함.

3. 이제 셋팅 들어간다. 위의 1, 2는 하나의 솔루션에 있어야 한다.
  - 가장 중요한 것!! tools > options >  debugging > general > 마지막줄의 use managed compatibility mode 체크.
  - 솔루션에 속성 설정 > common properties > project dependencies >  여기서 c# 프로젝트는 c++ dll 프로젝트에 의존한다고 체크
  - c#프로젝트에 속성 설정 > debug > Enable Debuggers > Enable native code debugging 체크!!!
  - c#프로젝트를 set as startup project

4. 이제 준비는 끝났으니 c++ 코드에 브레이크 포인트 걸고 F5



3번에 중요하다고 한 부분이 내가 고생한 부분이다. 인터넷에서 c++ dll을 c#에서 로드하는 상황에서 디버깅하는 방법을 검색해봤는데 저 말을 찾을 수 없었다. 어딘가 누군가는 적어놨겠지만...아무튼 저 부분이 매우 중요하다.

만약에 use managed com... 이 것을 체크하지 않은 상태라면 이상한 현상이 발생한다.
 - enable native code... 이 옵션을 체크하면 c++에 브레이크 포인트가 작동하지 않는다.
 - enable native code... 이 옵션을 해제하면 c++에 브레이크 포인트가 작동은 하지만 변수값을 제대로 볼 수 없다.

그런데 인터넷에서 흔히 찾을 수 있는 글들에는 오히려 enable native code... 를 해제하면 브레이크 포인트를 쓸 수 없다는 식으로 설명하기 때문에 굉장히 혼란스럽다.
아마도 vs2013의 사소한 버그인듯...

다행인 것은 c#에서 c++ dll을 로드한 상태로 디버깅을 시도하면 use managed com... 이 옵션을 켜야한다고 메세지가 뜬다.
문제는 이 메세지가 제법 길기 때문에 실수로 확인버튼 눌러서 닫으면 옵션이 어디에 있는지 찾기 힘들다는 것.
나는 대충 읽고 옵션을 찾으려고 했는데 tools에서 안찾고 c#프로젝트에서 찾아 들어가는 바람에 ....그 때 부터 대혼란이 시작되었다 orz





Posted by 세모아
,