Reputation: 21
Hello everyone got an error on debugging my application written in c# this is the error:
Use of unassigned local variable "SHELLEXECUTEINFO"
THIS IS THE ERROR LINE cbSize = Marshal.SizeOf(sHELLEXECUTEINFO),
i dont know why i get this error or how to correct it.
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;
}
Upvotes: 1
Views: 354
Reputation: 941545
Your initializer is using the variable before it is initialized. A common chicken-and-egg problem with initializers. You could just use the other overload:
Form1.SHELLEXECUTEINFO sHELLEXECUTEINFO = new Form1.SHELLEXECUTEINFO()
{
cbSize = Marshal.SizeOf(typeof(Form1.SHELLEXECUTEINFO)),
lpFile = pWOLocation,
// etc...
};
Or the more general solution:
Form1.SHELLEXECUTEINFO sHELLEXECUTEINFO = new Form1.SHELLEXECUTEINFO()
{
lpFile = pWOLocation,
// etc...
};
sHELLEXECUTEINFO.cbSize = Marshal.SizeOf(sHELLEXECUTEINFO));
Ask somebody to review your code btw.
Upvotes: 3
Reputation: 98750
The C# compiler does not allow the use of uninitialized variables. Looks like you didn't initialize your sHELLEXECUTEINFO
variable before you use it.
Upvotes: 0