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 /clr:oldSyntax:
TSEShared.h
--------------
// TSEShared.h
#pragma once
#include <string>
using namespace System;
namespace TSEShared {
public __gc class Global
{
public:
static std::string ToCppString(System::String *);
};
}
TSEShared.cpp
----------------
#include "stdafx.h"
#include "TSEShared.h"
std::string TSEShared::Global::ToCppString(System::String * str)
{
if (str == 0)
{
return(std::string());
}
System::IntPtr ptr(System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(str));
std::string ret(static_cast<const char *>(static_cast<void *>(ptr)));
System::Runtime::InteropServices::Marshal::FreeCoTaskMem(ptr);
return(ret);
}
Called from another assembly using /clr:oldSyntax
UseTSEShared.h
------------------
#pragma once
//#include <string>
//---------------------------------------------------------------------------
namespace UseTSEShared
{
public __gc class SomeClass {
public:
SomeClass();
};
}
UseTSEShared.cpp
--------------------
#include "stdafx.h"
#include "UseTSEShared.h"
UseTSEShared::SomeClass::SomeClass()
{
TSEShared::Global::ToCppString(0); // compiler error on this line
}
I do not see the reason why
I am trying to create resuable functions in an assembly which have mixed types in its signature. Clearly this should be doable. When I tried it with a __nogc class, I received an error that functions with clr calling conventions can not be exported. Now that I try it with a __gc class, I receive this error.

Candidate function(s) not accessible strange case
SeeBee
krus
By reporting the bug, the owners will take a look straight ahead and hence answer most of your questions as soon as they can.If that is a limitation that they were aware of (by design) then they would be able to suggest how to get around it.
Thanks, Ayman Shoukry VC++ TeamMohammadSamara
Mike Bouck
BadMojo
Dylan McAtee
Your reply means to me that you and the VC++ team understand that what I describe above can not be done in Visual Studio 2005 C++, essentially having a re-usable function in an assembly whose signature has mixed mode types.
Were you aware of this before you put out the product, or has my report just made you aware of this limitation If you were aware of this, did any of the VC++ developers suggest that such a limitation was not good for VC++ when programmed in .NET
I am curious, because in Visual Studio 2003 one could export a function which had CLR types in its signature, although there the C++ loader lock problem made any mixed mode DLL written in C++ pretty chancy to use. While you solved the loader lock problem, Visual Studio 2005 no longer allows a function to be exported which has a CLR type in its signature and now the problem I discuss here exists because of it. While I like the idea that I can now create assemblies in C++ doing mixed mode programming, naturally I do not enjoy this new limitation of C++ .NET programming.
tom_g
Thanks!
Could you please post a link to the bug reported so that others can follow up on the status of the issue in the furture
Thanks, Ayman Shoukry VC++ TeamKeith Buik
Alexey Monastyrsky
nelson rodriguez
Could you report the issues at http://lab.msdn.microsoft.com/productfeedback/default.aspx and describe why that would be an interesting scenario for you. I am sure that could help us planning for next versions.
Thanks, Ayman Shoukry VC++ TeamWendellwithSBSatMS
abrewerton