来自C#的PathYetAnotherMakeUniqueName或PathMakeUniqueName API调用 [英] PathYetAnotherMakeUniqueName or PathMakeUniqueName API call from C#

查看:112
本文介绍了来自C#的PathYetAnotherMakeUniqueName或PathMakeUniqueName API调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使api PathYetAnotherMakeUniqueName工作。

这是我到目前为止所拥有的。它不起作用。我缺少什么?


const int MAX_PATH = 260;


[DllImport(" shell32.dll",EntryPoint =" PathMakeUniqueName" ;)

static extern int PathMakeUniqueName(

ref string pszUniqueName,

int cchMax,

string pszTemplate,

string pszLongPlate,

string pszDir

);


[DllImport(" shell32。 dll",EntryPoint =" PathYetAnotherMakeUniqueName")]

static extern int PathYetAnotherMakeUniqueName(

ref string pszUniqueName,

string pszPath,
string pszShort,

string pszFileSpec

);


public void Test()

{

DirectoryInfo working = new DirectoryInfo(@" .. \..\");


string buffer = new string ('''',MAX_PATH);

string folderSpec = working.FullName;

string name =" New Text Document.txt";

PathYetAnotherMakeUniqueName(ref buffer,folderSpec,null,name);


}


~Paul

I''m having trouble getting the api PathYetAnotherMakeUniqueName to work.
Here is what I have so far. It is not working. What am i missing?

const int MAX_PATH = 260;

[DllImport("shell32.dll", EntryPoint="PathMakeUniqueName")]
static extern int PathMakeUniqueName (
ref string pszUniqueName,
int cchMax,
string pszTemplate,
string pszLongPlate,
string pszDir
);

[DllImport("shell32.dll", EntryPoint="PathYetAnotherMakeUniqueName")]
static extern int PathYetAnotherMakeUniqueName (
ref string pszUniqueName,
string pszPath,
string pszShort,
string pszFileSpec
);

public void Test()
{
DirectoryInfo working = new DirectoryInfo(@"..\..\");

string buffer = new string('' '', MAX_PATH);
string folderSpec = working.FullName;
string name = "New Text Document.txt";

PathYetAnotherMakeUniqueName(ref buffer, folderSpec, null, name);

}

~ Paul

推荐答案

嗨Paul,
Hi Paul,
我在api PathYetAnotherMakeUniqueName工作时遇到了麻烦。
这里是我到目前为止。它不起作用。我错过了什么?


使用StringBuilder作为第一个参数:

[DllImport(" shell32.dll",EntryPoint =" PathMakeUniqueName")]
static extern int PathMakeUniqueName(


StringBuilder pszUniqueName,

int cchMax,
string pszTemplate,
string pszLongPlate,
string pszDir
);
I''m having trouble getting the api PathYetAnotherMakeUniqueName to work.
Here is what I have so far. It is not working. What am i missing?
Use a StringBuilder for the first argument:
[DllImport("shell32.dll", EntryPoint="PathMakeUniqueName")]
static extern int PathMakeUniqueName (
StringBuilder pszUniqueName,
int cchMax,
string pszTemplate,
string pszLongPlate,
string pszDir
);



StringBuffer buffer = new StringBuffer(MAX_PATH);

...

PathYetAnotherMakeUniqueName(buffer ,folderSpec,null,name);


bye

Rob


StringBuffer buffer = new StringBuffer(MAX_PATH);
...
PathYetAnotherMakeUniqueName(buffer, folderSpec, null, name);

bye
Rob




使用StringBuilder允许调用正确返回,但值不是正确的
。它只返回路径而不是文件名。任何想法?


StringBuilder buffer = new StringBuilder(MAX_PATH);

PathYetAnotherMakeUniqueName(buffer," D:\",null," File .txt");


通话后缓冲的价值只是D:\


谢谢,
~Paul

" Robert Jordan" < RO ***** @ gmx.net>在消息中写道

news:cl ************* @ news.t-online.com ...
Hi,

Using StringBuilder allows the call to return correctly but the value is not
correct. It returns just the path and not the file name. Any ideas?

StringBuilder buffer = new StringBuilder(MAX_PATH);
PathYetAnotherMakeUniqueName(buffer, "D:\", null, "File.txt");

The value of buffer after call is just "D:\"

thanks,
~ Paul
"Robert Jordan" <ro*****@gmx.net> wrote in message
news:cl*************@news.t-online.com...
嗨Paul,
Hi Paul,
我无法使api PathYetAnotherMakeUniqueName工作。
这是我到目前为止所拥有的。它不起作用。我缺少什么?
I''m having trouble getting the api PathYetAnotherMakeUniqueName to work.
Here is what I have so far. It is not working. What am i missing?



使用StringBuilder作为第一个参数:



Use a StringBuilder for the first argument:

[DllImport(" shell32.dll",EntryPoint =") ; PathMakeUniqueName")]
static extern int PathMakeUniqueName(
[DllImport("shell32.dll", EntryPoint="PathMakeUniqueName")]
static extern int PathMakeUniqueName (



StringBuilder pszUniqueName,



StringBuilder pszUniqueName,

int cchMax,
string pszTemplate ,
字符串pszLongPlate,
字符串pszDir
);
int cchMax,
string pszTemplate,
string pszLongPlate,
string pszDir
);



StringBuffer buffer = new StringBuffer(MAX_PATH);
...
PathYetAnotherMakeUniqueName(buffer,folderSpec,null,name);

再见
Rob


StringBuffer buffer = new StringBuffer(MAX_PATH);
...
PathYetAnotherMakeUniqueName(buffer, folderSpec, null, name);

bye
Rob



嗨Paul,
Hi Paul,
使用StringBuilder允许调用正确返回,但值不正确。它只返回路径而不是文件名。有什么想法吗?

StringBuilder buffer = new StringBuilder(MAX_PATH);
PathYetAnotherMakeUniqueName(buffer," D:\",null," File.txt");

呼叫后缓冲区的值只是D:\
Using StringBuilder allows the call to return correctly but the value is not
correct. It returns just the path and not the file name. Any ideas?

StringBuilder buffer = new StringBuilder(MAX_PATH);
PathYetAnotherMakeUniqueName(buffer, "D:\", null, "File.txt");

The value of buffer after call is just "D:\"




请发布非托管声明。

bye

Rob



Please post the unmanaged declaration.

bye
Rob


这篇关于来自C#的PathYetAnotherMakeUniqueName或PathMakeUniqueName API调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆