4

I'm trying to write some C# code that uses the DIA (Debug Interface Access) SDK to query a PDB file. I used the batch file described in this question to create a wrapper assembly around the DIA type library. Now I was able to create instances of the different COM classes exposed by the SDK.

However, there appeared a problem. The IDiaDataSource::loadDataForExe method requires a callback object that implements one of the following interfaces:

  • IDiaLoadCallback
  • IDiaLoadCallback2
  • IDiaReadExeAtOffsetCallback
  • IDiaReadExeAtRVACallback

All of these interfaces are defined in the IDL, however they are not available in the generated .NET assembly.

Am I missing something, or is the only way to implement these interfaces in C# is to first manually declare them using the various COM attributes?

Community
  • 1
  • 1
Michael Bikovitsky
  • 903
  • 2
  • 10
  • 20
  • possible duplicate of _[How do I use the MS DIA SDK from C#?](http://stackoverflow.com/questions/697541/how-do-i-use-the-ms-dia-sdk-from-c)_ –  Apr 23 '15 at 11:58
  • @MickyDuncan, I don't think so. I tried the method described there, and the results were incomplete (as described in my question). – Michael Bikovitsky Apr 23 '15 at 12:02
  • Look in OleView to see if the interface is defined there. Also refer to the TypeLibs at the bottom. Perhaps they are not registered on your system? –  Apr 23 '15 at 12:05
  • requirements met? Header: Dia2.h lib: diaguids.lib DLLs: msdia80.dll – relascope Apr 23 '15 at 12:06
  • Like p-invoke, I find that once you cross a certain threshold, you are arguably better off writing a c++/CLI wrapper than redefining everything in .NET (particularly those COM systems that don't expose a type library). If you are experienced in both you'll find c++ end of COM much easier with it's 20+ year history of tooling and class libraries. –  Apr 23 '15 at 12:10
  • Just checked, and the type library _does not_ contain the interfaces. – Michael Bikovitsky Apr 23 '15 at 12:16

1 Answers1

3

Yes, this is a problem, the generated type library does not contain these interfaces. Something you can see by running OleView.exe, View + Typelib command, it shows the content of the type library, decompiled back to IDL syntax. Note how IDiaLoadCallback et al are missing.

This is an authoring problem in the IDL, it doesn't byte in C++ projects that use DIA but does if you depend on the type library for definitions. The issue is that Midl.exe will optimize the type library and only include declarations that are present or referenced in the [library] section. And since these are callback interfaces, none of the [coclass] declarations use these interfaces. So they are omitted from the type library.

It is pretty simple to fix. First copy dia2.idl to another directory or filename so you don't damage the original. And then edit the copy, simply cut-and-paste these four interfaces into the [library] section. Rebuild the type library with the documented Midl.exe command. Problem solved.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536