開發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.進行到這個地方基本上沒有其他問題了。然後我們添加一個安裝項目,進行安裝並且
運行該服務就會啓動起來了。