开发windows Service的过程中遇到一个问题:
我们要开发的程序中用到了华为的动态库函数的调用
但是华为这个动态库,用我们平时的添加reference是不能
够添加成功的,具体原因也不是很清楚。
具体解决步骤如下:
1.后来把华为的
dll动态库直接拷贝到bin目录下,然后在windows Serverice
中的"依赖项"通过添加assembly的方式把化为的动态库给添加过去。
2.调用华为动态库函数的方法如下:
[DllImport("SMEntry.dll")]
public static extern int SubmitShortMessage(string AtTime, string SourceAddr, string DestAddr, string Content, uint ContentLen, byte NeedStateReport, string ServiceID, string FeeType, string FeeCode);
private static void Message_Send(string destAddr,string content)
进行函数的声明。
编写我们自己的函数,其中一定要调用华为的原函数,我们可以进行参数传递。
3,我们进行到这个地方问题还是没有解决,原因是动态库的这种调用方式
需要指定一个命名空间来进行支持上述操作。
命名空间为:
using System.Runtime.InteropServices;
4.进行到这个地方基本上没有其他问题了。然后我们添加一个安装项目,进行安装并且
运行该服务就会启动起来了。