gpt4 book ai didi

c# - 使用未分配的局部变量 “SHELLEXECUTEINFO”

转载 作者:行者123 更新时间:2023-12-02 10:44:37 25 4
gpt4 key购买 nike

大家好,在调试用C#编写的应用程序时出错
这是错误:

使用未分配的局部变量“SHELLEXECUTEINFO”

这是错误线cbSize = Marshal.SizeOf(sHELLEXECUTEINFO),

我不知道为什么我得到这个错误或如何纠正它。

private bool PWOLaunch(int iTab)
{
string pWOLocation = Settings.Default.PWOLocation;
if (!File.Exists(pWOLocation))
{
this.openFileDialog1.ShowDialog();
pWOLocation = this.openFileDialog1.FileName;
if (!pWOLocation.Contains("PWO.exe"))
{
MessageBox.Show("Failed to Locate file: PWO.exe\nThis bot is only for Pokemon World Online!");
return false;
}
if (pWOLocation.Contains("PWO.exe"))
{
Settings.Default.PWOLocation = pWOLocation;
Settings.Default.Save();
}
}
Form1.PROCESS_INFORMATION pROCESSINFORMATION = new Form1.PROCESS_INFORMATION();
Form1.STARTUPINFO sTARTUPINFO = new Form1.STARTUPINFO();
Form1.SECURITY_ATTRIBUTES sECURITYATTRIBUTE = new Form1.SECURITY_ATTRIBUTES();
Form1.SECURITY_ATTRIBUTES sECURITYATTRIBUTE1 = new Form1.SECURITY_ATTRIBUTES();
Form1.SHELLEXECUTEINFO sHELLEXECUTEINFO = new Form1.SHELLEXECUTEINFO()
{
cbSize = Marshal.SizeOf(sHELLEXECUTEINFO),
lpFile = pWOLocation,
nShow = 1,
lpVerb = "runas",
fMask = 64
};
if (!Form1.CreateProcess(pWOLocation, null, ref sECURITYATTRIBUTE, ref sECURITYATTRIBUTE1, false, 32, IntPtr.Zero, null, ref sTARTUPINFO, out pROCESSINFORMATION))
{
MessageBox.Show("Failed to Launch file: PWO.exe");
return false;
}
StringBuilder stringBuilder = new StringBuilder("ThunderRT6FormDC");
IntPtr zero = IntPtr.Zero;
while (zero == IntPtr.Zero)
{
zero = this.FindProcessWindow(stringBuilder, pROCESSINFORMATION.dwProcessId);
}
if (!this.EmbedGame(zero, iTab))
{
MessageBox.Show("Failed to launch game into bot");
}
this.gameWindowHandles[iTab] = zero;
this.gameProcesshandles[iTab] = pROCESSINFORMATION.dwProcessId;
this.gameBotHandles[iTab] = IntPtr.Zero;
this.gameLogHandles[iTab] = IntPtr.Zero;
Form1.ShowWindow(this.gameWindowHandles[1], 0);
this.launchAllToolStripMenuItem.Text = "Restart Game";
return true;
}

最佳答案

您的初始化程序正在使用变量,然后再对其进行初始化。初始化程序常见的鸡和蛋问题。您可以使用其他重载:

    Form1.SHELLEXECUTEINFO sHELLEXECUTEINFO = new Form1.SHELLEXECUTEINFO()
{
cbSize = Marshal.SizeOf(typeof(Form1.SHELLEXECUTEINFO)),
lpFile = pWOLocation,
// etc...
};

或更一般的解决方案:
    Form1.SHELLEXECUTEINFO sHELLEXECUTEINFO = new Form1.SHELLEXECUTEINFO()
{
lpFile = pWOLocation,
// etc...
};
sHELLEXECUTEINFO.cbSize = Marshal.SizeOf(sHELLEXECUTEINFO));

请其他人检查您的代码。

关于c# - 使用未分配的局部变量 “SHELLEXECUTEINFO”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21885311/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com