英文:
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?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论