国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開發(fā) > 綜合 > 正文

C#使用技巧--調(diào)用DLL

2024-07-21 02:22:08
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
使用c#時(shí)不免用調(diào)用別的dll,如win32的api和自己以前做的dll,
c#調(diào)用dll很像vb,下面討論的c#調(diào)用dll的方式。
看看下面的例子,演示了怎么定義dll函數(shù)接口
public class utility
{
   [dllimport("kernel32",
entrypoint=”createdirectory”,
callingconvention=callingconvention.stdcall]
   public static extern bool create (string name);
  
   [dllimport("user32"]
entrypoint=”messagebox”,
callingconvention=callingconvention.stdcall]
   public static extern int msgbox (string msg);
}
  
class myclass
{
   public static int main()
   {
      string mystring;
      console.write("enter your message: ");
      mystring = console.readline();
      return utility.msgbox(mystring);
   }
}
  
值得注意的是,缺省的調(diào)用規(guī)則(callingconvention)是stdcall,同winapi,在
c++里是__stdcall的形式,函數(shù)入口(entrypoint)缺省是同名,如createdirectory
的定義也可以為
   [dllimport("kernel32")]
   static extern bool createdirectory(string name, securityattributes sa);
  
win32 api原型為
bool createdirectory(
  lpctstr lppathname,                         // directory name
  lpsecurity_attributes lpsecurityattributes  // sd
);
  
在調(diào)用win32 api時(shí)注意那些類型的轉(zhuǎn)換,如結(jié)構(gòu)(struct)、指針(pointer),

有關(guān)各種語(yǔ)言之間類型轉(zhuǎn)換和dllimport屬性的詳細(xì)信息可以參考sdk文檔 
上一篇:索引指示器

下一篇:使用C# Indexer

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 杭州市| 壤塘县| 荆门市| 凉城县| 嫩江县| 航空| 肇庆市| 建德市| 武夷山市| 周口市| 渭源县| 周宁县| 沛县| 曲周县| 闻喜县| 洛南县| 宾阳县| 平顶山市| 肇州县| 阜城县| 清新县| 安徽省| 宣恩县| 永吉县| 东安县| 海兴县| 额尔古纳市| 金湖县| 宜兴市| 肇源县| 大安市| 呼图壁县| 亚东县| 沾化县| 博罗县| 新营市| 桃园市| 昌吉市| 阳城县| 阳城县| 昌吉市|