4
votes

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?

1
possible duplicate of How do I use the MS DIA SDK from C#?MickyD
@MickyDuncan, I don't think so. I tried the method described there, and the results were incomplete (as described in my question).Michael Bikovitsky
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?MickyD
requirements met? Header: Dia2.h lib: diaguids.lib DLLs: msdia80.dllrelascope
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.MickyD

1 Answers

3
votes

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.