DarioN1
DarioN1

Reputation: 2552

c++ CLI Export void return __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention

I'm trying to export some void/functions from a C++ Cli that wraps C# .Net Functions.

In this moment I can properly export methods that return integer value, but when I try to export a Void, I get the error:

Error C3395 'Test2': __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention ClassLibrary1

This is the full code:

#pragma once

using namespace System;
using namespace System::Reflection;
using namespace RobinHoodLibrary;

namespace ClassLibrary1 {

    public ref class Class1
    {
        // TODO: Add your methods for this class here.
        RobinHood^ robin = gcnew RobinHood();

        public: int Add(int Number1, int Number2)
        {
            return robin->Add(Number1, Number2);
        }

        public: System::Void Test()
        {
            robin->Test();
        }

        public: int Test1(int i)
        {
            return robin->Test1(i);
        }

        public: System::Void Test2(String^ txt)
        {
            robin->Test2(txt);
        }

    };
}

extern __declspec(dllexport) int Add(int Number1, int Number2) {
    ClassLibrary1::Class1 c;
    return c.Add(Number1, Number2);
}

extern __declspec(dllexport) void Test() {
    ClassLibrary1::Class1 c;
    c.Test();
    return;
}

extern __declspec(dllexport) int Test1(int i) {
    ClassLibrary1::Class1 c;
    return c.Test1(i);
}

extern __declspec(dllexport) System::Void Test2(String^ txt) {
    ClassLibrary1::Class1 c;
    c.Test2(txt);   
}

I can easy export Add, Test and Test1 method but not Test2.

How can I to fix it ?

Thanks to support

Upvotes: 0

Views: 1863

Answers (2)

try with gcroot<> in function Test2 like this:

System::Void Test2(gcroot<String^> txt);

Upvotes: 0

user2033775
user2033775

Reputation: 153

AFAIK You can't export methods which have C++/CLI types in arguments or in return value. So you have to use const wchar_t* or std::wstring as parameter instead of String^.

Upvotes: 2

Related Questions