<p>I have a wrapper around a C++ function call which I call from C# code. How do I attach a debugger in Visual Studio to step into the native C++ code?</p>

<p>This is the wrapper that I have which calls GetData() defined in a C++ file:</p>

<pre><code>    [DllImport("Unmanaged.dll", CallingConvention=CallingConvention.Cdecl, 
               EntryPoint = "GetData", BestFitMapping = false)]
        public static extern String GetData(String url);
</code></pre>

<p>The code is crashing and I want to investigate the root cause.</p>

<p>Thanks,
Nikhil</p>

[{'answer_id': 57862, 'author': 'Lou', 'author_id': 4341, 'author_profile': 'https://Stackoverflow.com/users/4341', 'pm_score': 6, 'selected': True, 'text': '<p>Check the Debug tab on your project\'s properties page. There should be an "Enable unmanaged code debugging" checkbox. This worked for me when we developed a new .NET UI for  our old c++ DLLs.</p>\n\n<p>If your unmanaged DLL is being built from another project (for a while ours were being built using VS6) just make sure you have the DLL\'s pdb file handy for the debugging.</p>\n\n<p>The other approach is to use the C# exe as the target exe to run from the DLL project, you can then debug your DLL normally.</p>\n'}, {'answer_id': 57880, 'author': 'Rob Walker', 'author_id': 3631, 'author_profile': 'https://Stackoverflow.com/users/3631', 'pm_score': 3, 'selected': False, 'text': '<p>in addition to Lou\'s advise for starting the debugger, you can select which debug engines are used when attaching to an existing process by clicking on \'Select...\' in the \'attach to process\' dialog and choosing both \'managed code\' and \'native code\'.</p>\n\n<p>Debugging in this way is called mixed mode debugging.  See this <a href="http://blogs.msdn.com/sripod/archive/2006/12/05/debugging-mixed-mode-applications.aspx" rel="noreferrer">blog post</a> for some tips.</p>\n\n<p>I believe this isn\'t supported for 64 bit processes ... though would love to be wrong on that point.</p>\n'}, {'answer_id': 58954, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': "<p>To anyone using WinDbg:</p>\n\n<p>1>Setup symbols</p>\n\n<p>Look at these commands. (Help: in console .hh &lt; command> )</p>\n\n<pre><code>.sympath\n.sympath+ \n.symfix\n</code></pre>\n\n<p>2>Set up source path</p>\n\n<pre><code>.srcpath\n</code></pre>\n\n<p>3>Load SOS extention to debug managed / mixed mode programs.</p>\n\n<p>(Make sure you have extention path setup correctly)</p>\n\n<p>Add Microsoft.NET\\Framework\\v2.0.50727 for x86 using-</p>\n\n<pre><code>.extpath \n</code></pre>\n\n<p>Set a breakpoint for the clr to load.</p>\n\n<pre><code>sxe ld:mscorwks\n</code></pre>\n\n<p>(F5 / g)\n(Wait for  ModLoad BP on mscorwks.dll)</p>\n\n<p>Make sure you dont have a duplicate sos extention already loaded. See:</p>\n\n<pre><code>.chain\n</code></pre>\n\n<p>Now we're ready to load the sos extention. :)</p>\n\n<pre><code>.loadby sos mscorwks\n</code></pre>\n\n<p>4> Reload all the symbols..</p>\n\n<pre><code>.reload\n</code></pre>\n\n<p>Now you're all set :)</p>\n\n<p>(YMMV)</p>\n"}, {'answer_id': 732196, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>Mixed debugging is not  supported in 64bit mode (as of Visual Studio 2008).</p>\n'}]
['https://Stackoverflow.com/questions/57840', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5734/']