C# 运行dll时出现的问题

C# 运行dll时出现的问题,c#,c++-cli,C#,C++ Cli,构建dll时没有错误,但它不起作用 单击时,程序中会出现一个按钮,此时会显示消息“TEST”。 但是,尽管在构建时没有发出任何信号,但该按钮只是不出现 C#中的代码完全相同,但在cli中需要 我的DllExport: #pragma region Usings #include "stdafx.h" using namespace System; using namespace System::Runtime::InteropServices; #pragma endregion name

构建dll时没有错误,但它不起作用

单击时,程序中会出现一个按钮,此时会显示消息“TEST”。 但是,尽管在构建时没有发出任何信号,但该按钮只是不出现

C#中的代码完全相同,但在cli中需要

我的DllExport:

#pragma region Usings
#include "stdafx.h"
using namespace System;
using namespace System::Runtime::InteropServices;


#pragma endregion

namespace RGiesecke
{
    namespace DllExport
    {
        /// <summary>
        /// Used to control how to create an unmanaged export for a static method.
        /// </summary>
        /// <remarks>
        /// You are not bound to using this class in this assembly.
        /// By default, any attribute named "RGiesecke.DllExport.DllExportAttribute.DllExportAttribute" will do the trick.
        /// Even if it is declared to be only visible inside the assembly with the static methods you want to export.
        /// In such a case the naming and typing of the fileds/properties is critical or otherwise the provided values will not be used.
        /// </remarks>
        [AttributeUsage(AttributeTargets::Method, AllowMultiple = false)]
        private ref class DllExportAttribute : Attribute
        {
            /// <summary>
            /// Initializes a new instance of the <see cref="DllExportAttribute"/> class.
            /// </summary>
        public:
            DllExportAttribute()
            {
            }

            /// <summary>
            /// Initializes a new instance of the <see cref="DllExportAttribute"/> class.
            /// </summary>
            /// <param name="exportName">Name of the unmanaged export.
            /// <seealso cref="ExportName"/></param>
            DllExportAttribute(String ^exportName) //: DllExportAttribute(exportName, System::Runtime::InteropServices::CallingConvention::StdCall)


            {


            }


            /// <summary>
            /// Initializes a new instance of the <see cref="DllExportAttribute"/> class.
            /// </summary>
            /// <param name="exportName">Name of the unmanaged export.
            /// <seealso cref="ExportName"/></param>
            /// <param name="callingConvention">The calling convention of the unmanaged .
            /// <seealso cref="CallingConvention"/></param>
            DllExportAttribute(String ^exportName,  System::Runtime::InteropServices::CallingConvention callingConvention)
            {

                ExportName = exportName;
                CallingConvention = callingConvention;
            }

        private:
            static  System::Runtime::InteropServices::CallingConvention CConv = safe_cast< System::Runtime::InteropServices::CallingConvention>(0);


            /// <summary>
            /// Gets or sets the calling convention that will be used by the unmanaged export.
            /// </summary>
            /// <value>The calling convention.</value>
        public:
            property  System::Runtime::InteropServices::CallingConvention CallingConvention
            {
                 System::Runtime::InteropServices::CallingConvention get()
                {
                    return CConv;
                }
                void set( System::Runtime::InteropServices::CallingConvention value)
                {
                    CConv = value;
                }
            }

        private:
            String ^ExpName;

            /// <summary>
            /// Gets or sets the name of the unmanaged export.
            /// </summary>
            /// <value>The name of the export.</value>
        public:
            property String ^ExportName
            {
                String ^get()
                {
                    return ExpName;
                }
                void set(String ^value)
                {
                    ExpName = value;
                }
            }
        };
    }
}

请看代码,给我一些线索?

< P>看起来你的C++和C++ + CLI概念混淆了,合并它们都不起作用。p>
  • 在C++/CLI中,您不必将任何内容标记为DllExport。使类公开并编译它。在C#中,以与C#DLL相同的方式将其添加为引用
  • 我不知道你为什么要创建自己的DllExportAttribute。如果你自己做,那么.Net编译器不会对它做任何事情
以下是您需要做的所有事情:

  • 删除类DllExportAttribute
  • 只需将C++/CLI类定义为带有公共方法的公共类

    namespace Class2
    {
        public ref class Class1
        {
        public:
            double static ISHDAN(String ^connTemp, String ^connEoi, String ^cex, String ^SV, String ^SO, String ^izd, String ^TP, String ^cher)
            {
                MessageBox::Show("TEST");
                return 1;
            }
        };
    }
    
  • 像调用C#中的普通方法一样调用此方法


朋友需要所有代码才能在c++/cli上工作。试着详细解释一下,如果我能成为一名非批发程序员,我是一名实习生。我不能输入dll所连接的项目代码,我必须将dll放入根文件夹,重点是相同的dll只在c上,只需要在c++/cliA上出现按钮-什么按钮?我在代码中没有看到任何内容。
namespace Class2
{
    public ref class Class1
    {
    public:
        double static ISHDAN(String ^connTemp, String ^connEoi, String ^cex, String ^SV, String ^SO, String ^izd, String ^TP, String ^cher)
        {
            MessageBox::Show("TEST");
            return 1;
        }
    };
}
static void Main(string[] args)
{
    Class2.Class1.ISHDAN("temp", "eoi", "cex", "sv", "so", "izd", "tp", "cher");
}