今天在写一个wpf小程序时,少了2行代码,程序运行的结果就不一样了
调用dll 的语句如下:
[DllImport(@"Lib\TFReader.dll", EntryPoint = "oln_GetHidlist")]
private extern static int oln_GetHidlist(StringBuilder hidList, ref int usbCount);
功能部分代码如下
string TempBase = AppDomain.CurrentDomain.BaseDirectory;
Environment.CurrentDirectory = TempBase + "Lib";
TFReader tfReader = new TFReader();
if (tfReader.OpenReader())
{
tfReader.ReadCard(ref cardInfo);
MessageBox.Show(cardInfo.ToString());
}
如图,左边是我在不加
string TempBase = AppDomain.CurrentDomain.BaseDirectory;
Environment.CurrentDirectory = TempBase + "Lib";
时的中间值,右边是我在控制台界面调用该dll时的中间值(两个变量只是名字不同)
在没有这两句的时候,调用dll时返回的值就是-100
https://blog.csdn.net/weixin_42116284/article/details/80736143