Debug the WPF view code embedded in the MFC program with

Source: Internet
Author: User
I posted the Q & A process via email, hoping to help other friends who encountered similar problems:

When I encountered such a problem at work, I used vs2008 to write an executableProgramThis MFC program is embedded with the WPF view. I use the OCX developed by vs2010 to hold this WPF view. My problem is that if I use vs2008 to debug the MFC program, how can I enable the environment debugging of vs2010 when I need to call the WPF program in it. Net program?

A:

If you are debugging, a process cannot be attached to both debuggers at the same time. If you are debugging the MFC program with vs 2008, you will start the MFC project by default, vs 2008 uses native debug to add and debug the MFC program. After the program is started:

  1. You can choose "debug"> "detach from process" in the vs 2008 menu (sorry, I have no Chinese version of vs at hand, but I do not know the translation of Chinese, I had to write the original English text), so vs 2008 is out of the MFC process.
  2. Then you can use vs 2008 or vs 2010 to debug the WPF in MFC.CodeIn practice, click "debug"> "attach to process (attach to process...) in the vs menu ....) ", in the new" attach to process "dialog box, select" select "next to the" attach to: "text box ".
  3. In the pop-up "Select Code Type" dialog box, select "Debug these code types" and select "managed (v4.0)" in the list (If your WPF is 4.0 ), or "managed (V2.0, V1.1, V1.0)" (If your WPF is 2.0 ).
  4. Click OK to close the "Select Code Type" dialog box.
  5. In the "available process" list, find your process and click "Attach" to debug it.


The figure below shows my vs interface. You can view the above steps and perform operations with. 

 

 

Q:

I mean, debugging at the same time, vs08 debugging MFC, vs2010 debugging WPF, because there is interaction between the two. In addition, vs2010 writes an OCX that is called by MFC and wants to open vs2010 and load the wpf pdb file when it is started. They can work together

 

A:

There are some methods to debug the MFC and WPF code at the same time, but you cannot use two debuggers, because a process cannot be simultaneously attached by both debuggers, however, you can debug C ++ and WPF code simultaneously in a debugger. There are several methods: The following example is demonstrated using the example program provided by vs. The file path is: \ Program Files \ Microsoft Visual Studio 10.0 \ samples \ 1033 \ vc2010samples \ c ++ \ MFC \ wpfinterop If you cannot see the above path \ Program Files \ Microsoft Visual Studio 10.0 \ samples \ 1033 \ vc2010samples.zip Decompress the package. 1. Open the EXE debugging method directly:
    1. Start Visual Studio. It is recommended that you enable Visual Studio in the same way as before.
    2. Select "file"-"open"-"Project/SOLUTION" from the vs menu"
    3. In the open project dialog box, select the EXE file of your MFC Program (note that it is an EXE file ).
    4. Select EXE in "Solution Explorer", right-click it, and select "properties"
    5. In the Properties dialog box, change "Debugger type"'s default "Auto" to "mixed ".
    6. Then you can set breakpoint debugging in the C ++ and C # code.
    7. As shown in:

2. Methods in the project:
    1. Open the MFC project with Visual Studio
    2. Right-click Properties of the project
    3. On the project properties page, select "debug" and change "Debugger type" to "hybrid"
    4. As shown in:

 

3. Additional methods:
    1. Start the MFC program, and then start.
    2. Select "debug"-"attach to process" from the vs menu"
    3. In the pop-up "attach to process" dialog box, select "select" next to the "attach to:" text box ".
    4. In the pop-up "Select Code Type" dialog box, select "Debug these code types" and select "managed (v4.0)" in the list (If your WPF is 4.0 ), or "managed (V2.0, V1.1, V1.0)" (If your WPF is 2.0 ).
    5. And check "native", indicating that both the management and native code are debugged.
    6. Click OK to close the "Select Code Type" dialog box.
    7. In the "available process" list, find your process and click "Attach" to debug it.
    8. As shown in:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.