Cra*_*her 5 .net c# asp.net pinvoke
当我尝试使用平台调用示例时,我正在尝试更改字符串的Lower和Upper大小写时出错.
这是我到目前为止所得到的:
class Program
{
[DllImport("User32.dll", EntryPoint = "CharLowerBuffA",
ExactSpelling = false,
CharSet = CharSet.Unicode,
SetLastError = true
)]
public static extern string CharLower(string lpsz);
[DllImport("User32.dll",
EntryPoint = "CharUpperBuffA",
ExactSpelling = false,
CharSet = CharSet.Unicode,
SetLastError = true
)]
public static extern string CharUpper(string lpsz);
static void Main(string[] args)
{
string l = "teSarf";
string ChangeToLower = CharLower(l.ToLower());
string ChangeToUpper = CharUpper(l.ToUpper());
Console.WriteLine("{0}", ChangeToLower);
Console.ReadLine();
}
}
Run Code Online (Sandbox Code Playgroud)
我不知道我在哪里出错,但我认为这与EntryPoint有关.
我必须使用Unicode,而且CharLowerBuffW也不起作用.
我怎样才能解决这个问题?
Microsoft 的文档表明这CharLowerBuffA是该方法的 ANSI 变体,但您指定的是 Unicode。
尝试使用 ANSI - 通过指定CharSet = CharSet.Ansi- 或者如果您需要 Unicode,请使用CharLowerBuffW和CharUpperBuffW。
同样,该方法有两个参数。你没有第二个。所以试试这个:
[DllImport("User32.dll", EntryPoint = "CharLowerBuffW",
ExactSpelling = false,
CharSet = CharSet.Unicode,
SetLastError = true
)]
public static extern string CharLower(string lpsz, int cchLength);
[DllImport("User32.dll",
EntryPoint = "CharUpperBuffW",
ExactSpelling = false,
CharSet = CharSet.Unicode,
SetLastError = true
)]
public static extern string CharUpper(string lpsz, int cchLength);
Run Code Online (Sandbox Code Playgroud)
并这样称呼它:
string ChangeToLower = CharLower(l, l.Length);
Run Code Online (Sandbox Code Playgroud)
如果这仍然不起作用,那么尝试使用字符数组,就像 NatarajC 提到的那样。
| 归档时间: |
|
| 查看次数: |
66 次 |
| 最近记录: |