
Signature
Kapil Khosla, Visual C++ Team
This posting is provided AS IS with no warranties, and confers no rights
> Using VS2005Beta 2 I have VC++/CLI class defined in a Class Library DLL as:
>
[quoted text clipped - 22 lines]
> 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
Tamas Demjen - 08 Jun 2005 01:58 GMT
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
> 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