I have simple code:
msclr::interop::marshal_context ctx;
System::String ^converted =
msclr::interop::marshal_as<String^>(Directory::GetCurrentDirectory);
array<String^>^ files =
Directory::GetFiles(converted, "*.cpp", System::IO::SearchOption::AllDirectories);
I'm just trying to get current directory and then get a files in that folder, and all subfolders. But I'm getting the following error:
Error C3374 can't take address of 'System::IO::Directory::GetCurrentDirectory' unless creating delegate instance
I'm not sure why you need to try to marshal the method like that. Try calling it directly:
System::String^ converted = Directory::GetCurrentDirectory();
array<String^>^ files =
Directory::GetFiles(converted, "*.cpp", System::IO::SearchOption::AllDirectories);
Directory::GetCurrentDirectory
already returns a System.String^
so you don't need to marshal or convert it. Directory::GetCurrentDirectory
with parentheses like this: Directory::GetCurrentDirectory()
.