【问题标题】:Source not Available VS 2012源不可用 VS 2012
【发布时间】:2013-12-22 21:31:14
【问题描述】:

源不可用不断弹出

我已经在谷歌上搜索了很长一段时间,我看到的大多数解决方案都是更改 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

【问题讨论】:

  • 您需要通过调试找出导致问题的代码行并找出您缺少的源库。您可以设置断点以查看是否到达某个位置并缩小范围。
  • 退出事件处理程序时出现错误

标签: c# winforms visual-studio-2012 dll event-handling


【解决方案1】:

您应该检查并确保正在查看您的所有源文件,尤其是您导入的外部库。转到解决方案并正确的属性。在窗口中弹出[下面]转到调试源文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-10
    • 1970-01-01
    相关资源
    最近更新 更多