0

I've a native C++ DLL that I want to convert into a managed DLL using the C++\CLI mixed-mode feature. I've written some code. The compilation of the DLL is fine, but the compilation of the executable that exploits the DLL fails with the

error C3767 candidate function(s) not accessible

relative to the DLL's function I want to export. The structure of the code is the following

// -- DLL Header managedTest.h
namespace managedTest
{
    public ref class managedDLL
    {
    public:
        // -- Native function to export
        void SomeFunction(int a, USER-DEFINED TYPE &b);
    }
}

// -------------------------------------------------------------------------

// -- DLL cpp file managedTest.cpp
#include "managedTest.h"
void managedTest::managedDLL::SomeFunction(int a, USER-DEFINED TYPE &b)
{
     do something;
}

//--------------------------------------------------------------------------

// -- Implementation file that recalls the DLL
using namespace managedTest;
int main(void)
{
     managedDLL^ test = gcnew managedDLL;
     test->SomeFunction(a, b); // -- Here I have the error!
}

I have read something about the calling of a function across a managed-unmanaged boundary, but I still can't find a solution to this problem. I'm almost sure the problem is related to making public the USER-DEFINED TYPE.

Could someone help me understand what is the problem? Thank you in advance.

WestWizard
  • 51
  • 7
  • 1
    What is the USER-DEFINED TYPE? A struct? A class? A typedef? – David Yaw Nov 24 '15 at 20:10
  • 1
    Not a public managed type by the sound of it. So it can't be exported by the .NET metadata. Which makes the exposed method inaccessible. `#pragma make_public` might be a workaround but not often, wrap it as well.. – Hans Passant Nov 24 '15 at 20:13
  • Related: [C++ CLI error C3767: candidate function(s) not accessible](http://stackoverflow.com/questions/947213/c-cli-error-c3767-candidate-functions-not-accessible), [why is “candidate function(s) not accessible” although declared public](http://stackoverflow.com/questions/8400176/why-is-candidate-functions-not-accessible-although-declared-public) – crashmstr Nov 24 '15 at 20:18
  • @DavidYaw the USER-DEFINED TYPE is a struct. – WestWizard Nov 24 '15 at 20:23
  • @HansPassant I've already tried your suggestion about the #pragma but it didn't solve the problem. Is there no other way to solve the problem, either changing the structure of the program? – WestWizard Nov 24 '15 at 20:23
  • 1
    Please show the actual definition of the struct. To do this, it would need to be declared [public value struct](https://msdn.microsoft.com/en-us/library/ke3a209d.aspx) and none of the public members can be standard C++ classes. – crashmstr Nov 24 '15 at 20:30
  • 1
    Why do you have to change the "structure of the program"? Declaring a `public value class` to wrap the native structure is not different from declaring a `public ref class` to wrap the native class/functions. – Hans Passant Nov 24 '15 at 20:30

0 Answers0