如何将整数作为错误代码返回



我目前正在编辑一个.dll文件并尝试返回一个整数作为错误代码。我真的不知道我该如何实现这一目标。由于我找不到 C# 的类似内容,所以我在这里问。我正在尝试编辑的当前代码是这样的:

public bool LaunchExploit()
{
if (ExploitAPI.NamedPipeExist(this.cmdpipe))
{
MessageBox.Show("Dll already injected", "No problems");
}
else if (this.IsUpdated())
{
if (this.DownloadLatestVersion())
{
if (this.injector.InjectDLL())
{
return true;
}
MessageBox.Show("DLL failed to inject", "Error");
}
else
{
MessageBox.Show("Could not download the latest version! Did your firewall block us?", "Error");
}
}
else
{
MessageBox.Show("Patched", "Error");
}
return false;
}

我尝试将字符串作为错误返回,但由于这是一个public bool我无法这样做。任何想法如何返回整数作为错误代码

如果声明可以更改,也许这个会很有用:

public bool LaunchExploit(out int errorCode)
{
if (ExploitAPI.NamedPipeExist(this.cmdpipe))
{
errorCode = 1;
MessageBox.Show("Dll already injected", "No problems");
}
else if (this.IsUpdated())
{
if (this.DownloadLatestVersion())
{
if (this.injector.InjectDLL())
{
return true;
}
errorCode = 2;
MessageBox.Show("DLL failed to inject", "Error");
}
else
{
errorCode = 3;
MessageBox.Show("Could not download the latest version! Did your firewall block us?", "Error");
}
}
else
{
errorCode = 4;
MessageBox.Show("Patched", "Error");
}
return false;
}

最新更新