Symlink Windows

113 Views Asked by At

I'm trying to create a Symlink Generator with c++/cli ( Windows based ) There is a Docu on Microsoft ( MS )

But i dont know excactly how it works.

I tryed to find a working excample, but i could not find one and i could not get a working solution on my own.

My Complete Code HERE!

private: System::Void btnCreateSymlinks_Click(System::Object^  sender, System::EventArgs^  e) {
  String^ pathSource = GetSourcePath();
  String^ pathDest = GetDestinationPath();
  String^ folder = System::IO::Path::GetFileName(pathSource);
  lblInfo->Text = pathSource + " -> " + pathDest + "" + folder;
}

How do i use the CreateSymbolicLink function with those pathSource and pathDest?

1

There are 1 best solutions below

9
On BEST ANSWER

In order to use .NET strings on the garbage collected stack, you'll need pinning pointers (this is something that p/invoke does automatically for C# coders, but C++/CLI coders need to request).

pin_ptr<const wchar_t> wcsTarget = PtrToStringChars(pathSource);
pin_ptr<const wchar_t> wcsSymlink = PtrToStringChars(Path::Combine(pathDest, folder));

Then just call the Unicode version of the API (since .NET strings are always Unicode).

CreateSymbolicLinkW(wcsSymlink, wcsTarget, 0U);