对象引用未设置为对象的实例 - 请使用clarfy [英] Object reference not set to an instance of an object - pls clarfy
本文介绍了对象引用未设置为对象的实例 - 请使用clarfy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
当我运行我的代码时,我正在gging null引用错误。请告诉我如何纠正这个错误。
我的代码:xaml.cs
hi all,
when i run my code, i am ggeting null reference error. pls clarify me how to rectify this error.
my code : xaml.cs
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.Runtime.InteropServices;
namespace Mosaicimage
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
[DllImport("regkeydll.dll")]
public static extern int regmethod(string regname);
private void Application_Startup(object sender, StartupEventArgs e)
{
bool security = RegKeyDLL.SetRegistry.regmethod("Mosaic");
if (security)
{
Window1 mainWindow = new Window1();
mainWindow.Show();
}
}
}
}
这是一行,我收到此错误。
bool security = RegKeyDLL.SetRegistry.regmethod(Mosaic);
请告诉我如何纠正...
提前谢谢。
this is the line, where i am getting this error.
bool security = RegKeyDLL.SetRegistry.regmethod("Mosaic");
please clarify me how to rectify...
thanks in advance.
推荐答案
好吧,看看:你导入了这个功能来自C dll(至少,这是DllImport声明所说的)。当你想要执行那个方法时,你只需要调用它:
Well, look: you import that function from a C dll (at least, that''s what the DllImport statement says). When you want to execute that method, you just call it:
int security = regmethod("Mosaic");
另请注意,返回值根据您的声明为int,而不是bool。
Also note that the return value is int according to your declaration, not bool.
请参阅这里 [ ^ ] for如何在C#中设置密钥。
See here[^] for how to set keys in C#.
这篇关于对象引用未设置为对象的实例 - 请使用clarfy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文