Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dot net core C#带Process类的开放式照片查看器_C#_.net Core - Fatal编程技术网

Dot net core C#带Process类的开放式照片查看器

Dot net core C#带Process类的开放式照片查看器,c#,.net-core,C#,.net Core,我将使用.NETCore打开照片查看器,这是我的代码 using System.Diagnostics; namespace TestProcessForOpenPhoto { class Program { static void Main(string[] args) { var photoViewer = new Process(); photoViewer.StartInfo.FileName

我将使用.NETCore打开照片查看器,这是我的代码

using System.Diagnostics;
namespace TestProcessForOpenPhoto
{
    class Program
    {
        static void Main(string[] args)
        {
            var photoViewer = new Process();
            photoViewer.StartInfo.FileName = @"C:\Program Files\Windows Photo Viewer\PhotoViewer.dll";
            photoViewer.StartInfo.Arguments = @" C:\Users\XXXXX\Desktop\TestImage\abc.jpg";
            photoViewer.StartInfo.UseShellExecute = false;
            photoViewer.Start();
        }
    }
}

我收到了这个错误信息

System.ComponentModel.Win32Exception: 'The specified executable is not a valid application for this OS platform.'


有人能帮我修复这个错误吗,谢谢

在研究这个问题之后,我注意到有人使用
rundll32.exe
PhotoViewer.dll
执行导出以使用Microsoft Photo Viewer应用程序显示图片。所以我想这就是OP想要做的,他们只是忘记了使用
rundll32.exe
应用程序

所以我想我应该尝试一下,不要使用
rundll32.exe
,直接调用导出。我用x86dbg调试了它,发现它传入了4个参数:pointer,pointer,pointer(指向
wchar\t*
),int。我不知道这些参数是做什么的,所以我只是将它们设置为NULL,并确保以第三个参数的形式传入图片的路径,它似乎可以工作

所以这会做你想让它做的事。我知道硬编码系统路径是一种不好的做法,但也许有更多时间的人可以使其更具动态性

private static class WindowsPhotoViewer
{
    private const string FilePath32 = @"c:\program files (x86)\Windows Photo Viewer\PhotoViewer.dll";
    private const string FilePath64 = @"c:\program files\Windows Photo Viewer\PhotoViewer.dll";

    [DllImport(FilePath32, CharSet = CharSet.Unicode, EntryPoint = "ImageView_FullscreenW")]
    private static extern void ImageView_Fullscreen32(
        IntPtr unknown1, IntPtr unknown2, string path, int unknown3);

    [DllImport(FilePath64, CharSet = CharSet.Unicode, EntryPoint = "ImageView_FullscreenW")]
    private static extern void ImageView_Fullscreen64(
        IntPtr unknown1, IntPtr unknown2, string path, int unknown3);

    public static bool ShowImage(FileInfo imageFile)
    {
        if ((IntPtr.Size == 8) && File.Exists(FilePath64) && imageFile.Exists)
        {
            ImageView_Fullscreen64(IntPtr.Zero, IntPtr.Zero, imageFile.FullName, 0);
            return true;
        }
        else if ((IntPtr.Size == 4) && File.Exists(FilePath32) && imageFile.Exists)
        {
            ImageView_Fullscreen32(IntPtr.Zero, IntPtr.Zero, imageFile.FullName, 0);
            return true;
        }
        return false;
    }
}
那么你可以这样称呼它:

if(!WindowsPhotoViewer.ShowImage(new FileInfo(@"c:\users\andy\desktop\test.jpg")))
{
    Console.WriteLine("Failed to show image");
}

PhotoViewer.dll不是可执行文件。这是一个动态链接库。你不能执行这些。您可能需要从该DLL调用导出。您可能只需将
FileName
参数设置为
abc.jpg
路径,删除
参数
行,然后将
UseShellExecute
设置为
true
Greate@安迪,这对我有用!感谢一个lotBTW,我看到了一个解决方案,有什么不同?他们正在运行
rundll32.exe
来调用导出
ImageView\u全屏
存储在
PhotoViewer.dll
中。哦,这是一个非常好的示例,据我所知,您正在尝试导入查看器dll文件并用它打开图像,是吗?@EnergyBoy——是的。。。我直接在
PhotoViewer.dll
中调用导出的函数。基本上,它是在做
rundll32.exe
程序应该做的事情。对于你所需要的可能有点过分了!但是它似乎完成了任务。好的!我想你留给我的第一句话对我来说更简单。我会在将来学习这个,非常感谢!您好,安迪,我遇到一些问题,是否可以在windows服务中实现此功能?当我在调试模式下运行时,它运行平稳,但当我将其作为windows服务安装时,映像不会弹出up@EnergyBoy没有一点技巧是不可能的。看看这个: