error C3767: candidate function(s) not available

S

Steve Jaworski

Using VS2005Beta 2 I have VC++/CLI class defined in a Class Library DLL as:

#foo.h

namespace foo
{
public ref class Convert
{
public:
static Obj^ ToObj(UnmanagedObj* uObj);
};
}

Calling this static method from another VC++/CLI class in another Class
Library DLL as:

Obj^ obj = NULL;
obj = foo::Convert::ToObj(uObj);

results in a compilation error C3763: 'foo::Convert::ToObj': candidate
function(s) not accessible.

This worked fine in VS2003 and VS2005Beta1, any idea what's going on here?

Thanks,
Steve
 
G

Guest

--
Kapil Khosla, Visual C++ Team
This posting is provided AS IS with no warranties, and confers no rights


Steve Jaworski said:
Using VS2005Beta 2 I have VC++/CLI class defined in a Class Library DLL as:

#foo.h

namespace foo
{
public ref class Convert
{
public:
static Obj^ ToObj(UnmanagedObj* uObj);
};
}

Calling this static method from another VC++/CLI class in another Class
Library DLL as:

Obj^ obj = NULL;
obj = foo::Convert::ToObj(uObj);

results in a compilation error C3763: 'foo::Convert::ToObj': candidate
function(s) not accessible.

This worked fine in VS2003 and VS2005Beta1, any idea what's going on here?

Thanks,
Steve

The problem is with your native type in the managed function signature. From
what it looks like, that type is private and you must explicitly declare
public accessiblity for it.

Look at the previous thread on the same topic by searching for C3767 on
msdn.microsoft.com/visualc,

Thanks,
Kapil
 
T

Tamas Demjen

Steve said:
results in a compilation error C3763: 'foo::Convert::ToObj': candidate
function(s) not accessible.

I had the same problem before. I think this link is extremely helpful:
http://tinyurl.com/7fw59

If I understand it correctly, when you want to use native types in the
signature of public managed methods in an assembly, you have to make the
unmanaged class public for the assembly.

Try to add this line to your code:
public class __declspec(dllexport) UnmanagedObj {};

Let us know if this solves your problem.

Tom
 
T

Tamas Demjen

I've been doing an experiment to see if I can design a simple managed
wrapper around an unmanaged class, but faced a small problem that may be
a compiler bug.

I created an unmanaged DLL first:

// unmanaged.h
#ifdef UNMANAGED_EXPORTS
#define UNMANAGED_IMPORT __declspec(dllexport)
#else
#define UNMANAGED_IMPORT __declspec(dllimport)
#endif
#ifdef _MANAGED
public
#endif
class UNMANAGED_IMPORT UnClass
{
public:
int Square(int x) { return x * x; }
};

Then I created a managed assembly wrapper:

//managed.h
#pragma once
#include "unmanaged.h"
public ref class Class1
{
public:
Class1() : p(new UnClass) { }
~Class1() { delete p;}
UnClass* get() { return p; }
private:
UnClass* p;
};

And finally a managed test application:

// test.cpp
#include "unmanaged.h"
#using "managed.dll"
using namespace System;
int main(array<System::String^>^ args)
{
Class1 c;
UnClass* p = c.get();
p->Square(10); // this works
// c.get()->Square(10); // ERROR!!! why?
return 0;
}

I used the
#ifdef _MANAGED
public
#endif
trick to make my unmanaged class public, to avoid the "C3767: candidate
function not available" error, which the original poster had. It works
nicely.

However, there's one glitch. The following doesn't work in test.cpp:

c.get()->Square(10);

I get a compiler error C2039: 'Square': is not a member of 'UnClass'. I
don't understand why, it obviously is a member. I'm forced to assign the
output of the c.get() call to temporary variable 'p', or explicitly
cast, like this:

static_cast<UnClass*>(c.get())->Square(10);

Since c.get() returns UnClass*, the cast is not necessary, and I
shouldn't be getting a compiler error. Is this expected behavior, or is
it a bug in Beta 2?

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top