I’m testing a simple DLL, I wrote using C++/CLI, in a CLR console application. The DLL has only one function I’m trying to use. I’m referencing the DLL and set the Resolve #using Reference in the project property page, but I cannot see the function I wrote. I’m guessing I may have missed an access modifier somewhere, but I’m not sure. Here is a breakdown of my code:
DLL Code Header:
// LogDLL.h
#pragma once
#using <mscorlib.dll>
using namespace System;
namespace LogDLL {
public ref class LogFuncs
{
// TODO: Add your methods for this class here.
LogFuncs(){;};
~LogFuncs(){;};
void log_to_file ( System::String ^file, bool overwrite, System::String ^text );
};
}
DLL Code Source:
#include "stdafx.h"
#include "LogDLL.h"
using namespace System::Globalization;
void LogDLL::LogFuncs::log_to_file ( System::String ^file, bool overwrite, System::String ^text )
{
//Do Stuff
}
And the test code I’m using:
#include "stdafx.h"
#using <LogDLL.dll>
using namespace System;
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
LogDLL::LogFuncs^ a;
a::LogDLL::LogFuncs:: //<-- Intellisense doesn't show the function from the DLL
return 0;
}
Again, I’m not sure what I’m missing. It’s been awhile since I’ve worked with C++/CLI so I’m pretty rusty.
UPDATE:
I went ahead and changed the class to a struct per Peter’s advice.
Modified DLL Header Code:
// LogDLL.h
#pragma once
#using <mscorlib.dll>
using namespace System;
namespace LogDLL {
public ref struct LogFuncs
{
// TODO: Add your methods for this class here.
LogFuncs(){;};
~LogFuncs(){;};
void log_to_file ( System::String ^file, bool overwrite, System::String ^text );
};
}
What I still don’t understand is why the class would still default to private even though I specify it as public. Is there some fundamental reason why this is the case? Would it be any different if I was using unmanaged C++??
The default access for class is private. Either add “public:” for the members you want to be public or change to a ref struct, which has default access of public.
With respect to IntelliSense, I’m assuming you’re using Visual Studio 2005 or Visual Studio 2008; Visual Studio 2010 does not support IntelliSense for C++/CLI code (this is because the parser was replaced with EDG and they didn’t retrofit the C++/CLI parsing capabilities into it for 2010’s release).
I doubt IntelliSense would auto-complete with the syntax you’re using anyway. You’d want “a->” instead (of course, gcnew it before running this code).