DLL导入不适用于VS 2019模板

时间:2019-12-04 23:15:19

标签: c# dll tcp dllimport synchronizationcontext

我刚得到一个WinForm应用程序,其中包含导入的dll。当我使用现有的解决方案和csproj文件时,一切工作都很好,但是当我使用VS 2019创建一个新项目并将dll文件导入到该项目时,它根本不起作用。我已经将Platform更改为x86,并且将属性更改为在构建时始终包含dll。另外,我正在使用.csproj文件,但没有帮助。

[DllImport("KRComm.dll", CallingConvention = CallingConvention.StdCall)]
            static extern int OpenComm(int ACommType, int ACommPort, StringBuilder TCPAdr);
        [DllImport("KRComm.dll", CallingConvention = CallingConvention.StdCall)]
            static extern int CloseComm();
        [DllImport("KRComm.dll", CallingConvention = CallingConvention.StdCall)]
        static extern int GetLockStat(Int16 ALockAddr, RecvData recvdata);
        [DllImport("KRComm.dll", CallingConvention = CallingConvention.StdCall)]
        static extern int OpenLock(Int16 ALockAddr, RecvData recvdata); 

这就是将dll导入winform应用程序的方式。 另外,我相信dll建立了tcp连接,因此可以通过某种方式连接它吗?

更新 我注意到代码仅在winforms应用程序中运行,而不在控制台或webapp中运行,所以我在想这可能是由于同步上下文所致。我是否有可能因此失去打开的连接?

0 个答案:

没有答案
相关问题