任何人都可以向我指出一些代码示例,说明我如何实现像iOS中的那样的图库,在Windows 7上使用触摸屏显示器时,您可以左右滑动以更改图像?
当我为GetWindowText运行下面的代码时,我得到以下错误作为内部异常抛出:
{"尝试读取或写入受保护的内存.这通常表示其他内存已损坏."}
[DllImport("user32.dll", EntryPoint = "GetWindowTextLength", SetLastError = true)]
internal static extern int GetWindowTextLength(IntPtr hwnd);
[DllImport("user32.dll", EntryPoint = "GetWindowText", SetLastError = true)]
internal static extern int GetWindowText(IntPtr hwnd, ref StringBuilder wndTxt, int MaxCount);
try{
int strLength = NativeMethods.GetWindowTextLength(wndHandle);
var wndStr = new StringBuilder(strLength);
GetWindowText(wndHandle, ref wndStr, wndStr.Capacity);
}
catch(Exception e){ LogError(e) }
Run Code Online (Sandbox Code Playgroud)
我有两个问题:
为什么错误没有被try catch捕获?
任何想法,除了使用try/catch之外,当它遇到这种类型的错误时我怎么能阻止程序崩溃
干杯
下面的代码在我的 32 位机器上完美运行,但我现在已经在我的 64 位机器上测试了代码,我希望它能够像我调用 64 位版本的 cscript.exe 一样运行。
相反,代码会到达运行脚本的位置,然后等待 30 秒,然后退出脚本并继续程序的其余部分。然而,该脚本似乎没有运行(如果我手动运行它,它工作正常)。
using (var ServerProcess = new System.Diagnostics.Process())
{
var fileInformation = new FileInfo(VBScriptToRun);
string processFileName = IntPtr.Size == 8 ? @"c:\windows\sysWOW64\cscript.exe " : @"c:\windows\system32\cscript.exe ";
string processWorkDir = IntPtr.Size == 8 ? @"c:\windows\sysWOW64\" : @"c:\windows\system32\";
string processArguments = fileInformation.FullName;
ServerProcess.StartInfo.FileName = processFileName;
ServerProcess.StartInfo.WorkingDirectory = processWorkDir;
ServerProcess.StartInfo.Arguments = processArguments;
ServerProcess.StartInfo.CreateNoWindow = false;
ServerProcess.StartInfo.UseShellExecute = false;
ServerProcess.StartInfo.RedirectStandardOutput = true;
ServerProcess.StartInfo.LoadUserProfile = true;
EventLogger.Instance.WriteInformation("Total Integration Service Processing File: Starting to launch the …Run Code Online (Sandbox Code Playgroud)