Documenting C++/CLI library code for use from c# - best tools and practices? [closed] - documentation

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I'm working on a project where a c++/cli library is being used primarily from a c# application.
Is there any way to make the code comments in c++/cli visible to c# intellisence within visual studio?
Assuming there isn't, what would be the best way to document the c++/cli code to enable its easier use from c# (and within c++/cli of course)? What is you opinion on XML comments vs doxygen vs other tools (which)?

I have gotten it to work as follows:
Use XML style comments for your C++/CLI header entries. This means the full XML comment is required (triple-slash comments, <summary> tag at a minimum)
Make sure that the C++ compiler option Generate XML Documentation Files is on. This should generate an XML file with documentation with the same name as your assembly (MyDll.xml).
Make sure that the C# project references your assembly MyDll.dll where MyDll.xml is also present in the same folder. When you mouse over a reference from the assembly, MS Visual Studio will load the documentation.
This worked for me in Visual Studio 2008 on an assembly built for .NET 3.5.

DocXml has the major advantage of being supported by VS (syntax colouring, intellisense, automatic export to the XML files). The Doxygen tools can read DocXml format so you can still use them with this format too.
To help you generate tidy and accurate Doc comments with a minimum of effort, you might like to check out my addin AtomineerUtils. This takes most of the work out of creating and updating DocXml, Doxygen, JavaDoc or Qt format comments, and it supports C, C++, C++/CLI, C#, Java, JavaScript, TypeScript, JScript, UnrealScript, PHP and Visual Basic code.

Interesting. After trying several methods, it's looking like the intellisense between a Managed C++ project and C# doesn't work.
The following example will give you proper intellisense in the C++ environment where it is declared, but referencing the object in C# shows nothing:
// Gets the value of my ID for the object, which is always 14.
public: virtual property int MyId
{
int get() { return 14; }
}
XML comments don't work either. I would guess that this is either a bug, or requires something I can't figure out. Judging from the lack of answers on this question, perhaps a bug.
As far as documentation generation, I'd recommend going the path of XML documentation. Doxygen supports reading XML documentation which is mostly identical to the standard XML documentation for C#. It does tend to add extra lines just for tag openings and closings, but is much more readable in my opinion than the following doxygen alternative:
//! A normal member taking two arguments and returning an integer value.
/*!
\param a an integer argument.
\param s a constant character pointer.
\return The test results
\sa Test(), ~Test(), testMeToo() and publicVar()
*/

You are right. It doesn't work. The C++ build will add its IntelliSense information into the master .ncb file, and you will get the autocompletion of method names, etc. However, you are correct in that you will be unable to get the "comment" description about each method, etc.

You'll probably have a lot of value taking a look at Doxygen. And then look up Doxygen.NET - which is something we wrote for our own use which builds "Object Hierarchies" from the XML file outputs from Doxygen...

Related

VBA and late binding: Where do I find the numeric equivalents to constants?

I'm a complete VBA newbie, having decided to teach myself over a weekend, so forgive the stupid question(s). I'm trying to automate some routine tasks involving generating Word documents or emails from an Excel Spreadsheet. Because there will be multiple software versions involved, I am using late binding to open Word and Outlook. My question is: Where can I find a simple reference telling me what the index numbers are that correspond to the application constants? I have killed a lot of time googling to learn that, for example, the Outlook foldertype for "Contacts" is "10". Maybe someone knows of a web link that could save me countless hours of searching?
Update: http://msdn.microsoft.com/en-us/library/office/gg278936%28v=office.14%29.aspx seems to have some of the information I need, although it's not always intuitive where the information is. For example, if it contains the outlook folder type constants, I haven't found them yet.
See here
Enumeration http://msdn.microsoft.com/en-us/library/office/ff860961(v=office.15).aspx
OlDefaultFolders Enumeration http://msdn.microsoft.com/en-us/library/office/ff861868(v=office.15).aspx
I would recommend to add the relevant object libraries to your project as References during development time. You do this by using the Tools - References Menu in the VBA Editor. This makes developing a lot easier as you can use intellisense while writing the code.
If you need only a few Enums or single Constants in your code the easiest way to get their values is to hit [F2] in in VBA Editor while the object libraries are still referenced. Then search for the constants name and copy its value to your code.
Just using the numeric values of the constants in your code makes the code pretty hard to read. So I would recommend to re-declare all the Enums/Constants you actually use in a module in your own project. That massively improves the readability of your code.
So, instead of just copying the value from the VBA Object Browser, I suggest you copy the name and the value and put it your own code as a constant declaration. For your example of the Outlook contacts folder this will look like this:
Public Const olFolderContacts = 10
You can then use the constant in your procedures as you would do with Early Binding.
Should you work on a larger automation project using many of the constants from any one of the Office Object Libraries, you can download ready-made VBA modules containing all the Office constants from my website. You can then just import the relevant modules into your project and are ready to go.
After you finished the main development work, you remove the linked libraries from your project and declare the relevant object variables As Object instead of the actual type.
Always remember to compile your project not to miss any declaration that does not work late binding.

Xml documentation <code> tag shows C# for VB.NET code

I am trying to use the <code> tag inside the <example> tag to show a sample code in xml documentation. However, when I build the Sandcastle project, I see that it is shown as C#. There is no language attribute in <code> tag. And I could not find a setting in Sandcastle's project properties. Am I missing something?
BTW, I am using HtmlHelp1 format.
Actually, if you move beyond Sandcastle to Sandcastle Help File Builder (SHFB),
you will get both an easier to use interface to Sandcastle and additional features for your documentation set, including just what you want: a language attribute (language) for the <code> element.
Note that SHFB generates a language selector menu but that only lets you
show or hide a particular set of languages (C#, VB.NET, C++, J#, JScript.NET, XAML, and JavaScript). It supports colorizing, though, of a larger set (C#, VB.NET, JScript.NET, C++, J#, C, JavaScript, VBScript, XAML, XML, HTML, SQL script, PowerShell script, and Python). (From the Code Block Component section of the SHFB documentation.)
I have written extensively on this point, as well as many other tips and pitfalls of Sandcastle and SHFB, in my article Taming Sandcastle: A .NET Programmer's Guide to Documenting Your Code published on Simple-Talk.com. Besides the main article, I also put together a wallchart/quick reference that gives you everything you need to know to use Sandcastle/SHFB on one page--the link also appears at the end of the article.
You can find more details about the <code> element in the Displaying Sample Code section of my article, as well as from the official SHFB documentation at Importing and Colorizing Code from Source Files.

Changing VB.NET code programmatically

I want to open an existing VB class file, add a few properties and close it again.
Simple enough, I thought: Take the CodeDom, a VBCodeProvider, parse the code (using the Parse-method), then identify the location where I want my stuff added (doubtless using some nifty LINQ expressions), add a bit of code and then have it generated and here we go.
Now I see that Microsoft apparently added the Parse method only for the fun of it but never implemented it.
What's the story here? Can I only generate code from scratch? Is it not possible to load existing code?
Does anyone know of any solutions?
You say "class files" and then you say "parse". I think you meant "parse and modify".
Our DMS Software Reengineering Toolkit with its Visual Basic Front End can do what you need on VB.net source code files.
DMS provides general parsing, AST-building, generic analysis and AST transformations, and is able to regenerate source text in compilable form. The Visual Basic Front End enables DMS to process VB.net, VBScript or VB6 and carry out any of these activities.
DMS's Source-to-Source transformations can be used to make changes using "if-you-see-this, replace-it-by-that" patterns.

Doxygen and Assembly Language

I'd like to use Doxygen to document legacy code that's a mix of C and x86 assembly language. The assembly language is not inline, but in separate assembly-only files. How can I document the assembly language portion?
Question 12 of the Doxygen FAQ eventually led me to a Perl filter that looks promising. It converts the assembly code into something C-like that Doxygen can parse. Thanks!
The original link appears to be dead. However back in 2008, I had pulled down a copy of asm4doxy.pl and squirreled it away. I've put it up on Pastebin if anyone is still interested. As I recall, I tried it, but it didn't really work for me at the time, but YMMV.
See question 12 of the Doxygen FAQ. Are you dealing with pure assembly files, or inline assembly inside C sources? Assuming the former, you'll have to either write an input filter to transform the assembly code into something C-like (easier), or write a new parser (much harder).

VB.NET Aliases (as in C#)

There is Aliases feature in C# that allows to work with different assemblies, containing equally named entities (classes, structures, enums). It is activated when you choose an assembly an referenced assemblies list. But I can't see any similar in VB.NET project. Is there such a feature in VB.NET? If no, why?
Imports Data = System.Data
Will allow you to use:
Data.SqlClient
Similar to what you've seen in C#. Here is a blog post that discusses the usage. Here is an older one that laments another feature C# has that VB.NET doesn't (didn't?)
I think you are talking about the /reference:alias=filename option accepted by the C# compiler. That allows you to rename the root namespace of the assembly. Very handy when you need to reference both an old and a new version of an assembly that otherwise contain classes with the same namespace and class names. Without that option, you'd always get an ambiguous identifier compile error. The namespace alias feature can't fix that.
No, VB.NET doesn't have that. Why? Ask at connect.microsoft.com.
This is an example for how to do it, in both C# and VB.NET