HighTechTalks DotNet Forums  

Help converting to C++

VC++.net microsoft.public.dotnet.languages.vc


Discuss Help converting to C++ in the VC++.net forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
AA2e72E
 
Posts: n/a

Default Help converting to C++ - 02-05-2010 , 02:17 AM






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:irectoryInfo:irectoryInfo(System:: String ^)' : cannot convert
parameter 1 from 'System::IO:irectoryInfo ^' 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.

Reply With Quote
  #2  
Old   
Jochen Kalmbach [MVP]
 
Posts: n/a

Default Re: Help converting to C++ - 02-05-2010 , 02:27 AM






bool CDirectory(String^ path)
{
DirectoryInfo^ d = Directory::CreateDirectory(path);
return (d->Exists(path));
}

--
Greetings
Jochen

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

Reply With Quote
  #3  
Old   
AA2e72E
 
Posts: n/a

Default Re: Help converting to C++ - 02-05-2010 , 06:10 AM



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.


"Jochen Kalmbach [MVP]" wrote:

Quote:
bool CDirectory(String^ path)
{
DirectoryInfo^ d = Directory::CreateDirectory(path);
return (d->Exists(path));
}

--
Greetings
Jochen

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

Reply With Quote
  #4  
Old   
Jochen Kalmbach [MVP]
 
Posts: n/a

Default Re: Help converting to C++ - 02-05-2010 , 07:03 AM



Hi AA2e72E!

Quote:
_declspec (dllexport) bool _stdcall CDirectory(char path)
You are passing *one* character!


Quote:
2. What do ^ and * do?
^is a reference object.
* is a pointer.

Quote:
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/

Reply With Quote
  #5  
Old   
Carl Daniel [VC++ MVP]
 
Posts: n/a

Default Re: Help converting to C++ - 02-14-2010 , 10:36 AM



"AA2e72E" <AA2e72E (AT) discussions (DOT) microsoft.com> wrote

Quote:
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

Reply With Quote
  #6  
Old   
AA2e72E
 
Posts: n/a

Default Re: Help converting to C++ - 02-15-2010 , 05:54 AM



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.

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.