After calling the DLL, it crashes and flashes back. The following is the code of the method class.

huangapple go评论54阅读模式
英文:

After calling the DLL, it crashes and flashes back. The following is the code of the method class

问题

最近,我在学习制作一个表单程序演示。调用 DLL 后,程序崩溃并回退。

以下是代码:

[DllImport("vspdctl.dll", CallingConvention = CallingConvention.StdCall)]
public static extern bool CreatePair(string comName1, string comName2);

public bool CreatePort(string com1, string com2)
{
    string s = com1;
    string s2 = com2;
    bool IsCrateture = CreatePair(com1, com2);
    return IsCrateture;
}
private void button1_Click(object sender, EventArgs e)
{
    bool IsCrateSeccuss = GetVSPD.CreatePort(CreatePortName.Text, CreatePortName2.Text);
    if (IsCrateSeccuss)
    {
        MessageBox.Show("OK");
    }
    else
    {
        MessageBox.Show("Fail");
    }
}

报告了这个错误,错误如下:

System.DllNotFoundException: 无法加载 DLL 'vspdctl.dll':动态链接库 (DLL) 初始化例程失败。

不确定是什么原因引起的。

英文:

Recently, I was learning to make a form program Demo. After calling the DLL, it crashed and flashed back.

Below is the code:

`[DllImport("vspdctl.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern bool CreatePair(string comName1, string comName2);

public bool CreatePort(string com1,string com2)
        {
            string s = com1;
            string s2 = com2;
            bool IsCrateture=CreatePair(com1, com2);
            return IsCrateture;
        }`

`private void button1_Click(object sender, EventArgs e)
        {
                bool IsCrateSeccuss = GetVSPD.CreatePort(CreatePortName.Text, CreatePortName2.Text);
                if (IsCrateSeccuss)
                {
                    MessageBox.Show("OK");
                }
                else
                {
                    MessageBox.Show("Fail");
                }`

Reported this error, the error is as follows:

System.DllNotFoundException: Unable to load DLL 'vspdctl.dll': A dynamic link library (DLL) initialization routine failed.

Not sure what caused it

答案1

得分: 1

以下是翻译好的部分:

"The DLL file must be located in the current directory of the program or in the query path defined by the system (ie: the path set by Path in the system environment variable)"

DllNotFoundException 明确指出:当在 DLL 导入中指定的 DLL 无法找到时抛出的异常。

尝试使用 DllImportAttribute 直接添加 DLL 文件的目录。以下是一个参考示例:如何在运行时指定 [DllImport] 路径?

英文:

The DLL file must be located in the current directory of the program or in the query path defined by the system (ie: the path set by Path in the system environment variable)

DllNotFoundException clearly stated: The exception that is thrown when a DLL specified in a DLL import cannot be found.

Try using DllImportAttribute to directly add the directory of the dll. Here is a reference example: How can I specify a [DllImport] path at runtime?

huangapple
  • 本文由 发表于 2023年3月15日 21:33:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75745439.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定