2016-12-27 23 views
-1

我试图创建符号链接发生器,C++/CLI(基于Windows) 有微软(MS符号连接的Windows

一个的Docu但我不知道它excactly是如何工作的。

我tryed找到工作excample,但我无法找到一个和我不能让我自己一个可行的解决方案。

我的完整代码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; 
} 

如何使用这些pathSource和pathDest的CreateSymbolicLink功能?

+0

此[文章](http://community.bartdesmet.net/blogs/bart/archive/2006/10/24/Windows-Vista-_2D00_-Creating-symbolic-links-with-C_2300_.aspx ) 可能有帮助。 – tinstaafl

+0

它对于C#和我需要C++ – xQp

回答

2

为了使用垃圾收集堆在.NET字符串,你需要钉住指针(这是一件的P/Invoke的C#程序员自动完成,但C++/CLI程序员需要申请)。

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

然后只需调用Unicode版本的API(因为.NET字符串总是Unicode)。

CreateSymbolicLinkW(wcsSymlink, wcsTarget, 0U); 
+0

PtrToStringChars不与pin_ptr 至少对我来说我不知道​​ – xQp

+0

@xQp:你有所有的C++/CLI头已包括? –

+0

我tryed与http://stackoverflow.com/questions/9782669/c-cli-system-string-to-mfc-lpctstr位CreateSymbolicLinkW不工作 – xQp