开发者

Trying to upgrade to .NET Framework 4

开发者 https://www.devze.com 2023-03-12 08:48 出处:网络
I am trying to upgrade to the MS .NET Framework 4 and I am encountering an error with a dllimport function (see below). When the code reaches the dllimport, the program just exits with error code 0x80

I am trying to upgrade to the MS .NET Framework 4 and I am encountering an error with a dllimport function (see below). When the code reaches the dllimport, the program just exits with error code 0x80000003. I have tried changing it so the input and output are StringBuilder and I also tried setting the charset by both changing the charset (to either unicode or ansi) and setting a 开发者_如何学编程EntryPoint (either PathGetArgsA or PathGetArgsW). This code works fine in v3.5 but not in v4.

    [DllImport("Shlwapi.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern string PathGetArgs([In] string path);
    [DllImport("Shlwapi.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern void PathRemoveArgs([In, Out] StringBuilder path);
    public static bool ExtractArguments(string cmdLine, out string filePath, out string fileArgs)
    {
        StringBuilder strCmdLine = new StringBuilder(cmdLine.ToLower().Trim());

        filePath = fileArgs = "";

        if (strCmdLine.Length <= 0)
            throw new ArgumentNullException("cmdLine");


        fileArgs = string.Copy(PathGetArgs(strCmdLine.ToString())); // Error occurs here

        PathRemoveArgs(strCmdLine);

        filePath = string.Copy(strCmdLine.ToString());

        if (!string.IsNullOrEmpty(filePath))
            if (Utils.FileExists(filePath))
                return true;

        return false;
    }

Thanks!


I'm not sure what the native dll retuns in the PathGetArgs however, the Marshal Class could help.

[DllImport("Shlwapi.dll")]
public static extern IntPtr PathGetArgs([In] string path);

fileArgs = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(PathGetArgs(strCmdLine.ToString()));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号