简体   繁体   English

C#vs2015中的C ++ DLL XML文档注释

[英]c++ dll xml documentation comments in c# vs2015

i have a DLL written in C++ with some calculation functions. 我有一个用C ++编写的具有一些计算功能的DLL。
i use PInvoke (Platform Invoke) for using it in C# windows form. 我在C#Windows窗体中使用PInvoke(平台调用)。
i also have a XML documentation in the DLL folder. 我在DLL文件夹中也有XML文档。
i'm using Win7 x64 and updated VS2015 and x64 compiler in both sides. 我正在使用Win7 x64以及双方更新的VS2015和x64编译器。
Question: why i can't see comments in intelliSense in C#? 问题:为什么我在C#中看不到intelliSense中的注释? here is my C++ code 这是我的C ++代码

///<summary>this is sample</summary>  
extern "C" __declspec(dllexport) int __stdcall foo(int a, int b)
{
    int c = a*a + b*b;
    return c;
}

here is my C# code 这是我的C#代码

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        [DllImport("Project2")]
        public static extern int foo(int a, int b);

        private void Form1_Load(object sender, EventArgs e)
        {
            label1.Text = foo(4, 5).ToString();
        }
    }
}

the function works fine but i can't see documentation in intelliSense. 该功能工作正常,但我看不到intelliSense中的文档。
thanks. 谢谢。

You can create the XML documentation on the method in your C# code: 您可以在C#代码中的方法上创建XML文档:

    /// <summary>
    /// Does some stuff.
    /// </summary>
    /// <param name="a">Helps with stuff.</param>
    /// <param name="b">Also helps with stuff.</param>
    /// <returns>The result of doing stuff.</returns>
    [DllImport("Project2")]
    public static extern int foo(int a, int b);

Note that attribute sections are considered part of the method declaration, and as such, the XML documentation must precede these ( source ). 请注意,属性部分被视为方法声明的一部分,因此,XML文档必须在这些声明之前( source )。

Sorry for late Answer! 对不起,迟到的答案! I write my solution for others if they have same problem. 如果其他人有同样的问题,我会为他们写解决方案。 i found that for C++ PInvoke it is impossible. 我发现对于C ++ PInvoke,这是不可能的。 XML documentation is for .Net compliant codes. XML文档适用于.Net兼容代码。 I change my solution for that project to C++/CLI. 我将该项目的解决方案更改为C ++ / CLI。 and that was the solution! 那就是解决方案! C++/CLI is .Net compliant and fully support XML documentation. C ++ / CLI兼容.Net并完全支持XML文档。 also its referencing is different. 其引用也不同。 you simply add the C++/CLI project to your solution or add its dll to references. 您只需将C ++ / CLI项目添加到您的解决方案中,或将其dll添加到引用中。 C++/CLI in my opinion have some benefits and i think it doesn't have drawbacks in comparison with C++. 我认为C ++ / CLI有一些好处,与C ++相比,我认为它没有缺点。 i don't think it have been possible with PInvoke. 我认为PInvoke不可能实现。 Best Regards! 最好的祝福!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM