473,386 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Candidate function(s) not accessible [?]

Hello,

Sorry another question on mixed code assemblys.

I have a static class library containing a lot of unmanged code.

I have created a mixed code assembly which I am attempting to use in a
forms project.

Thus,

Class Library:

"Types.h"

class someType
{
public:
someType(double val);
//load of unmanaged stuff
};

//////////////////////////////////////////////////

CLR Library:

#include "Types.h"

using namespace System;

namespace CLRLibrary {

public ref class MyAssembly
{
public:
MyAssembly(const someType& val);

private:
someType m_value;
};
}

//////////////////////////////////////////////////
Forms project:
#include "Types.h"
double val = System::Convert::ToDouble(textBox1->Text);
CLRLibrary ::MyAssembly^ ass = gcnew CLRLibrary
::MyAssembly(someType(val));

//////////////////////////////////////////////////

Now, I cant see any reason why this wouldnt work - indeed this seems
like a perfectly reasonable thing to want to do.

Problem is when I build the solution I get:-

Form1.h(100) : error C3767: 'CLRLibrary::MyAssembly::MyAssembly':
candidate function(s) not accessible

Can anyone point me in the correct direction please? I have to admit to
getting a bit frustrated with C++/CLI

Aug 31 '06 #1
2 7854
<aj******@hushmail.comwrote
class someType
{
public:
someType(double val);
//load of unmanaged stuff
};

//////////////////////////////////////////////////

CLR Library:

#include "Types.h"
It's important to understand that in the CLR type
identity is comprised of the definining assembly and its full
name.

The C++ compiler translates native types (such as someType)
to CLR value types.

When you share an include file between two different projects
(or actually between two projects generating different PE modules),
you end up with two distinct value type definitions.
using namespace System;

namespace CLRLibrary {

public ref class MyAssembly
{
public:
MyAssembly(const someType& val);
By default, CLR value types emitted for native types are not exported.
That means there is no way (well, sort of) to refer to these from outside
the assembly.
Forms project:
#include "Types.h"
double val = System::Convert::ToDouble(textBox1->Text);
CLRLibrary ::MyAssembly^ ass = gcnew CLRLibrary
::MyAssembly(someType(val));
Form1.h(100) : error C3767: 'CLRLibrary::MyAssembly::MyAssembly':
candidate function(s) not accessible
I believe, the diagnostic tries to tell you that the ctor
is not accessible because on type in the signature is not visible
outside the assembly.

Consider the following example:

//t.cpp
struct N{};
public ref struct R { R( N* ){} };
// u.cpp
int main() { R r(0); }

// /clr:safe suppress a lot of metadata - you'll better understand ILDASM
cl /clr:safe /LD /wd4956 /wd4959 t.cpp
cl /clr /FUt.dll u.cpp
Can anyone point me in the correct direction please? I have to admit to
getting a bit frustrated with C++/CLI
You should try to avoid native types in managed signatures. Just use
standard C++ techniques (i.e. static libraries & header files) or
create wrappers for your types.

You can still use some hack to make the C++ compiler-generated
value type public (i.e. visible outside the assembly). But then you
shouldn't use #include to introduce your interface.

You can use a visibility specifier on your native types (i.e.:
public class someType{..}; )
and there's the make_public pragma.

-hg
Sep 1 '06 #2
Holger Grund wrote:
You should try to avoid native types in managed signatures. Just use
standard C++ techniques (i.e. static libraries & header files) or
create wrappers for your types.

You can still use some hack to make the C++ compiler-generated
value type public (i.e. visible outside the assembly). But then you
shouldn't use #include to introduce your interface.

You can use a visibility specifier on your native types (i.e.:
public class someType{..}; )
and there's the make_public pragma.

-hg
Many thanks for your reply.

I am having problems getting my head around how one would "properly"
design something using C++/CLI when using libraries of unmanaged code.

As I saw it I can create my static libraries of unmanaged code and then
create a series of assemblies that use this code but provide a managed
interface to this that refer to unmanged types.

I really dont want to provide a C++/CLI mapping class for each of the
unmanged types nor make these types managed.

For example I have a unmanaged struct that is used a lot in my
unmanaged library that contains a large number of ints/doubles that
seems a perfect candidate to be used in a managed function signature as
it isnt too complicated and to duplicate this structure in managed code
just so it can be used in a function signature seems *wrong*.

I have used make_public and my code compiles and links ok. But I am
concerned that this isnt a proper design solution.

Sep 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Anthony Baxter | last post by:
On behalf of the Python development team and the Python community, I'm happy to announce the first release candidate of Python 2.4. Python 2.4c1 is a release candidate - we'd greatly appreciate...
6
by: Bill Rubin | last post by:
The following code snippet shows that VC++ 7.1 correctly compiles a static member function invocation from an Unrelated class, since this static member function is public. I expected to compile the...
4
by: Adriano Coser | last post by:
I'm getting the following error: error C3767: PictureSource - candidate function(s) not accessible when accessing a public member function of a managed class, either from managed or unmanaged...
3
by: Steve Jaworski | last post by:
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);
0
by: quortex | last post by:
Hey, I have a problem which I have no clue how to fix. I am using the CLI and some of the ref class constructors require a native type to be passed in. Obviously because the 2005 CLI now...
0
by: Edward Diener | last post by:
When trying to call a __gc class static function in an assembly which has CLR and non-CLR types in its signature, I get a Candidate function(s) not accessible error. In an assembly, using...
2
by: Iwanow | last post by:
Hello! I have a single class without any inheritance over there, and I get that error on its constructor which is an empty function: LabelProcessor::LabelProcessor() { } The full error...
9
by: Gilbert | last post by:
Hi, In the code-behind, i have this function: Public Function myfunction(ByVal myvar As Object) As String dim x as string = myvar ..... Return x End Function
16
by: =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= | last post by:
On behalf of the Python development team and the Python community, I'm happy to announce the release of Python 2.5.2 (release candidate 1). This is the second bugfix release of Python 2.5. Python...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.