国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 肃宁县| 巴东县| 弋阳县| 武鸣县| 二连浩特市| 延川县| 新田县| 山阴县| 澄迈县| 抚顺县| 浦城县| 汉源县| 高阳县| 库伦旗| 阳信县| 靖江市| 水富县| 惠东县| 天长市| 老河口市| 方城县| 安溪县| 巴彦淖尔市| 吉安县| 台北县| 贵德县| 府谷县| 云浮市| 武山县| 凤冈县| 宣武区| 肥乡县| 安新县| 怀仁县| 思茅市| 江安县| 女性| 长岭县| 衡阳市| 清水县| 高密市|