c# - 带有进程类的点网核心 C# 打开照片查看器
问题描述
我将使用 .net core 打开照片查看器,这是我的代码
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.'
谁能帮我解决这个错误,谢谢
解决方案
在对此进行研究后,我注意到人们使用 Microsoft Photo Viewer 应用程序rundll32.exe
执行导出PhotoViewer.dll
以显示图片。所以我认为这就是 OP 试图做的,他们只是忘记使用该rundll32.exe
应用程序。
所以我想我会对此有所了解,而不是使用,rundll32.exe
而只是直接调用导出。我用 x86dbg 对其进行了调试,发现它传入了 4 个参数:指针、指针、指针 (to 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");
}
推荐阅读
- php - 此路由不支持 POST 方法。支持的方法:Laravel 中的 GET、HEAD
- c# - 无法从 Microsoft 服务写入键盘输出
- python - 弹性搜索采样聚合 UNKNOWN KEY
- xamarin.android - 连接到 WiFi 网络
- python - Python:将输入文本拆分为 {Letter}
- javascript - 即使静音自动播放,视频也无法在 Safari 和 Chrome 移动设备上播放
- xamarin.forms - 在另一个 ViewModel 中观察命令
- ios - 不更新和集成登录功能的现有应用程序会怎样?
- laravel - 将 Eloquent 参数与 DB::raw 而非 DB::select(DB:raw()) 绑定
- python - 如何使用 Anaconda 升级 TensorFlow?