How do I use the MS DIA SDK from C#?

前端 未结 3 1560
猫巷女王i
猫巷女王i 2020-12-15 00:05

I\'m trying to use the Microsoft Debug Interface Access SDK from C#. This is installed with Visual Studio, but the docs don\'t seem to mention how you use this from C#.

相关标签:
3条回答
  • 2020-12-15 00:31

    In case somebody has issues with the path, here is what worked for me for VS 2017.

    1. Open x86_x64 Cross Tools Command Prompt (from start/programs/Visual Studio 2017 in Administrator mode)

    2. cd C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional

    3. midl /I "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\DIA SDK\idl";"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\DIA SDK\include" dia2.idl /tlb dia2.tlb

    4. tlbimp dia2.tlb

    The Dia2Lib.dll is now in the C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional folder.

    Using it in C# code I got unregistered dll exception ! I had to run

    C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\DIA SDK\bin>regsvr32 msdia140.dll

    to get this resolved

    0 讨论(0)
  • 2020-12-15 00:45

    You need to convert the IDL to a typelib first:

    Something like:

    midl /I "%VSINSTALLDIR%\DIA SDK\include" dia2.idl /tlb dia2.tlb
    tlbimp dia2.tlb
    

    Then you can import the tlb.

    I've never used the DIA SDK this way, so don't know how friendly it would be. You could also consider using it directly from a managed C++ assembly and presenting a managed interface to the functionality you need.

    0 讨论(0)
  • 2020-12-15 00:47

    The previous instructions worked, but needed some updating. VSINSTALLDIR doesn't exist anymore (and is ambiguous when you have multiple VS versions installed) so I generalized and corrected the instructions. Here is a VS 2015 version:

    "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" amd64
    set DIASDK=%VS140COMNTOOLS%..\..\DIA SDK
    midl /I "%DIASDK%\include" "%DIASDK%\idl\dia2.idl" /tlb dia2.tlb
    tlbimp dia2.tlb
    

    Change VS140 to match whatever version you are trying to use.

    This created dia2lib.dll which I added as a reference - right-click References, Add Reference, Browse, find the file. It works and I can now build and run symbolsort.

    0 讨论(0)
提交回复
热议问题