源不可用继续弹出
我一直在谷歌搜索已经有一段时间了,我看到的大多数解决方案都在改变Visual Studio的设置,尝试了它们但仍然无法解决问题
我有以下代码
[DllImport("BS2dll.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool FiRE(int ptr, int l);
以另一种形式
public void createButton2()
{
int x = 0, y = 0;
butt2 = new Button[100];
for (int i = 0; i < 100; i++)
{
butt2[i] = new Button();
int names = i;
butt2[i].Name = "2" + names.ToString();
butt2[i].Location = new Point(520 + (x * 31), 70 + (y * 21));
butt2[i].Visible = true;
butt2[i].Size = new Size(32, 22);
butt2[i].BackColor = Color.CornflowerBlue;
this.Controls.Add(butt2[i]);
butt2[i].Click += new EventHandler(butt2_2_Click);
x++;
if (x == 10)
{
x = 0; y++;
}
}
}
事件处理程序
private void butt2_2_Click(object sender, EventArgs e)
{
bool hit;
int loc;
Button pushedBtn = sender as Button;
if (pushedBtn != null)
{
pushedBtn.BackColor = Color.Blue;
pushedBtn.Enabled = false;
loc = int.Parse(pushedBtn.Name);
if (loc > 29)
loc -= 200;
else
loc -= 20;
hit = UnsafeMethodCall.FiRE(objPtr, loc);
if (hit == true)
{
// MessageBox.Show("HIT");
pushedBtn.BackColor = Color.Red;
}
else
{
//MessageBox.Show("MISS");
pushedBtn.BackColor = Color.Black;
}
}
}//error appears around here
即使我评论hit = UnsafeMethodCall.FiRE(objPtr, loc);
它仍然存在
我的dll如果有帮助
void __stdcall FiRE(int *ptr, int l)
{
Battleship *dll = (Battleship *) ptr;
dll->FIRE(l);
}
bool Battleship::FIRE( int l) //check if hit or miss
{
for(int i= 0; i<17; i++)
{
if (board[i]==l)
{
hit = true;
break;
}
else
hit = false;
break;
}
return hit;
}
我的设置 Settings
所以我认为我的问题出在事件处理部分,因为即使我删除了对dll的调用,错误仍然存在
你可能已经注意到,这是一个战舰游戏 当我第一次打船时,它返回true,接下来的尝试只会返回false答案 0 :(得分:0)
您应该检查并确保正在查看所有源文件,尤其是对于您导入的外部库。转到解决方案并找到属性。在窗口中弹出[下方]转到调试源文件。