469,630 Members | 1,192 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,630 developers. It's quick & easy.

error C3767: candidate function(s) not available

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
Nov 17 '05 #1
3 5171

--
Kapil Khosla, Visual C++ Team
This posting is provided AS IS with no warranties, and confers no rights
"Steve Jaworski" wrote:
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

Nov 17 '05 #2
Steve Jaworski wrote:
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
Nov 17 '05 #3
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
Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Jess | last post: by
1 post views Thread by Alberto Menchen | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.