如何使用C#的MS DIA SDK?

时间:2022-05-10 20:42:52

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#.

我正在尝试使用C#的Microsoft Debug Interface Access SDK。这是随Visual Studio一起安装的,但是文档似乎没有提到你如何在C#中使用它。

I've found example code on interweb but no information on how to link to the DIA SDK. I.e. I can't import it as an assembly. I don't think I have to include it into a managed C++ application and use it as COM (that would be hell).

我在interweb上找到了示例代码,但没有关于如何链接到DIA SDK的信息。即我无法将其作为程序集导入。我不认为我必须将它包含在托管C ++应用程序中并将其用作COM(这将是地狱)。

There is an IDL file, is this the correct way? If so, how?

有一个IDL文件,这是正确的方法吗?如果是这样,怎么样?


Edit: The following will create the type library for use as a referenced assembly. Paste into a batch file.

编辑:以下将创建用作引用程序集的类型库。粘贴到批处理文件中。

call "%VS80COMNTOOLS%\vsvars32.bat"
midl /I "%VSINSTALLDIR%\DIA SDK\include" "%VSINSTALLDIR%\DIA SDK\idl\dia2.idl" /tlb dia2.tlb
tlbimp dia2.tlb

3 个解决方案

#1


You need to convert the IDL to a typelib first:

您需要先将IDL转换为类型库:

Something like:

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

Then you can import the tlb.

然后你可以导入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.

我从未使用过这种方式的DIA SDK,所以不知道它会有多友好。您还可以考虑直接从托管C ++程序集中使用它,并为您需要的功能提供托管界面。

#2


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

如果有人对路径有疑问,这就是VS 2017对我有用的东西。

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

    打开x86_x64交叉工具命令提示符(从管理员模式下的start / programs / Visual Studio 2017开始)

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

    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

    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.

Dia2Lib.dll现在位于C:\ Program Files(x86)\ Microsoft Visual Studio \ 2017 \ Professional文件夹中。

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

在C#代码中使用它我得到了未注册的DLL异常!我不得不跑

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

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

to get this resolved

解决这个问题

#3


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:

之前的说明有效,但需要进行一些更新。 VSINSTALLDIR不再存在(当你安装了多个VS版本时,它是不明确的)所以我概括并纠正了指令。这是一个VS 2015版本:

"%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.

更改VS140以匹配您尝试使用的任何版本。

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.

这创建了我添加的dia2lib.dll作为参考 - 右键单击​​引用,添加引用,浏览,找到该文件。它工作,我现在可以构建和运行符号。

#1


You need to convert the IDL to a typelib first:

您需要先将IDL转换为类型库:

Something like:

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

Then you can import the tlb.

然后你可以导入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.

我从未使用过这种方式的DIA SDK,所以不知道它会有多友好。您还可以考虑直接从托管C ++程序集中使用它,并为您需要的功能提供托管界面。

#2


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

如果有人对路径有疑问,这就是VS 2017对我有用的东西。

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

    打开x86_x64交叉工具命令提示符(从管理员模式下的start / programs / Visual Studio 2017开始)

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

    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

    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.

Dia2Lib.dll现在位于C:\ Program Files(x86)\ Microsoft Visual Studio \ 2017 \ Professional文件夹中。

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

在C#代码中使用它我得到了未注册的DLL异常!我不得不跑

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

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

to get this resolved

解决这个问题

#3


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:

之前的说明有效,但需要进行一些更新。 VSINSTALLDIR不再存在(当你安装了多个VS版本时,它是不明确的)所以我概括并纠正了指令。这是一个VS 2015版本:

"%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.

更改VS140以匹配您尝试使用的任何版本。

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.

这创建了我添加的dia2lib.dll作为参考 - 右键单击​​引用,添加引用,浏览,找到该文件。它工作,我现在可以构建和运行符号。