Help converting to C++

A

AA2e72E

I have two lines of basic C# code

System.IO.Directory.CreateDirectory(path);
return System.IO.Directory.Exists(path);

I want to bury this in a C++ Win32 Project. My effort so far (that does not
work and I do not understand the error messages) is:

#using <mscorlib.dll>

using namespace System;
using namespace System::IO;

bool* _clrcall;bool CDirectory(String path)
{
DirectoryInfo d = Directory::CreateDirectory(path);
return (d.Exists(path));
}

I get

Error 3 error C3149: 'System::String' : cannot use this type here without a
top-level '^'
Error 4 error C2664:
'System::IO::DirectoryInfo::DirectoryInfo(System::String ^)' : cannot convert
parameter 1 from 'System::IO::DirectoryInfo ^' to 'System::String ^'
Error 5 error C2064: term does not evaluate to a function taking 1 arguments


I would be grateful for some guidance/clues; thanks.
 
A

AA2e72E

Thank you; I'd be grateful for some more help.

1. Why is this always (even when the path exists) returning false:

_declspec (dllexport) bool _stdcall CDirectory(char path)
{
//DirectoryInfo d = Directory::CreateDirectory(path,"R");
if (Directory::Exists(path.ToString()))
{
return true;
}
else
{
return false;
}
}

2. What do ^ and * do?

3. Do I need to #include ? for String^ path to compile?

Thanks for your patience.
 
J

Jochen Kalmbach [MVP]

Hi AA2e72E!
_declspec (dllexport) bool _stdcall CDirectory(char path)

You are passing *one* character!

2. What do ^ and * do?

^is a reference object.
* is a pointer.
3. Do I need to #include ? for String^ path to compile?

No. You need to add a reference to mscorlib.dll and add
using namespace System;


May I ask you a question?
WHY are you using C++/CLI? Why not use C#?


--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
C

Carl Daniel [VC++ MVP]

AA2e72E said:
I want to bury this in a C++ Win32 Project. My effort so far (that does
not
work and I do not understand the error messages) is:

#using <mscorlib.dll>

using namespace System;
using namespace System::IO;

bool* _clrcall;bool CDirectory(String path)
{
DirectoryInfo d = Directory::CreateDirectory(path);
return (d.Exists(path));
}

This is NOT C++ Win32 code. This is C++/CLI code that still depends on the
CLR at runtime. If your aim was to not depend on the CLR, you'll need a
different solution.

-cd
 
A

AA2e72E

My VS2008 project is C++ Win32 Project; I understand that if I use _stdcall e.g

_declspec (dllexport) char* _stdcall to_upper(char *lowerstring)

I can use C++/CLI code within the body of the function. This allows the DLL
to be used by native i.e. unmanaged code clients.

It was not my intention to avoid the CLR.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top