为什么MessageBox.Show在该代码中不起作用?

时间:2019-03-31 19:55:04

标签: c# .net

我想在具有C#应用程序的64位Windows 8计算机上从Windows XP的32位shimgvw.dll运行ImageView_Fullscreen函数(目标框架:4,AppType:控制台应用)。函数根本不起作用,但是在调用MessageBox.Show之后,我看到了一张奇怪的图片。为什么是这样?请给我解释一下。 这是我的应用程序C#代码:

[DllImport("kernel32.dll", EntryPoint = "AddAtomW", CharSet = CharSet.Unicode)]
static extern ushort AddAtom(string lpString);

//shimgvw.dll is from WindowsXP (6.00.2900.5512 version)
//For ImageView_FullscreenW and CharSet.Unicode result is the same
[DllImport(@"D:\Graphic Soft\ShimgvwXP\shimgvw.dll", CharSet = CharSet.Ansi, EntryPoint = "ImageView_FullscreenA", SetLastError = true)]
static extern void ImageView_Fullscreen(IntPtr i, IntPtr dll, string path, int wndMode);

static void Main(string[] args)
{
    MessageBox.Show("Test"); //Working!
    AddAtom("FailObsoleteShellAPIs");   //Without that atom LoadLibrary fails

    IntPtr hinstance = LoadLibrary(@"D:\Graphic Soft\ShimgvwXP\shimgvw.dll");
    if (hinstance != IntPtr.Zero)
    {
        MessageBox.Show("Test"); //Working!

        //Not doing anything...Though it must show image. Image is exists
        ImageView_Fullscreen(IntPtr.Zero, hinstance, @"D:\Wallpapers\0001_2.jpg", 3);

        uint err = GetLastError();
        MessageBox.Show("Error: " + err); //NOT WORKING!!!
        Console.WriteLine("Error: " + err);  //Working. Prints out: "Error: 0"

        //Not doing anything...This image is NOT exists
        ImageView_Fullscreen(IntPtr.Zero, hinstance, @"D:\Wallpapers\not_existed_image.jpg", 3);

        err = GetLastError();
        MessageBox.Show("Error: " + err); //NOT WORKING!!!
        Console.WriteLine("Error: " + err);  //Working. Prints out: "Error: 2 (code ERROR_FILE_NOT_FOUND)"
    }

    Console.ReadKey();
}

1 个答案:

答案 0 :(得分:-2)

代替使用消息框, 您可以使用:

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), Guid.NewGuid().ToString().Trim(), "javascript:alert('This is my First Answer on Stack Overflow');", true);
            return;**

string abc = "StackOverFlow"; 

ScriptManager.RegisterClientScriptBlock((Page)(HttpContext.Current.Handler), typeof(Page), "alert", "javascript:alert('" + Convert.ToString(abc("Cannot Be Empty. ")) + "');", true); return;

enter image description here

相关问题