<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d4684235500622716427\x26blogName\x3dCaiwangqin\x27s+blog\x26publishMode\x3dPUBLISH_MODE_HOSTED\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttp://blog.caiwangqin.com/search\x26blogLocale\x3dzh_CN\x26v\x3d2\x26homepageUrl\x3dhttp://blog.caiwangqin.com/\x26vt\x3d3393395200455623441', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe", messageHandlersFilter: gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER, messageHandlers: { 'blogger-ping': function() {} } }); } }); </script>

Caiwangqin's blog

Focus on Life, Cloud Service, Smart Hardware, Architecture, Technic and beyond…

浅谈使用C#调用API函数

2005年10月1日星期六

  我本来是不打算在Blog上记录有关技术的细节问题的,今天一上网,巨澜的一个朋友从MSN请我帮助写一个Demo,使用C#调用API函数发送短信。我花了1小时左右做了程序,在此共享给大家,评述不够详尽请大家谅解,此文有抛砖引玉嫌 [sweat] 。

  在C#中调用API函数首先引用以下命名空间:


引用自

using System.Runtime.InteropServices;


  然后使用DllImport引入Dll文件,声明API函数的使用方法:


引用自

[DllImport("JL_ISP.dll",EntryPoint="JL_TCPLogin")]

static extern int JL_TCPLogin (

$nbsp$$nbsp$[MarshalAs(UnmanagedType.LPTStr)] string strHost,


$nbsp$$nbsp$int nPort,

$nbsp$$nbsp$[MarshalAs(UnmanagedType.LPTStr)] string strUserId,

$nbsp$$nbsp$[MarshalAs(UnmanagedType.LPTStr)] string strPassword,

$nbsp$$nbsp$int nType,

$nbsp$$nbsp$IntPtr pHandle);[/quote]

  做了上述声明,即可以C#中象使用用内部方法一样调用JL_TCPLogin方法了:


引用自

public int TCPLogin(string strHost,int nPort,string strUserId,string strPassword,int nType,IntPtr pHandle)

{

$nbsp$$nbsp$int bRtn = JL_TCPLogin(strHost,nPort,strUserId,strPassword,nType,pHandle);

$nbsp$$nbsp$return bRtn;

}


  示例文件提供下载,该Class只提供3个方法,且需要巨澜的JL_ISP.dll才能编译成功,但可从中参阅C#调用API函数的方法: 点击下载


标签:

posted by Caiwangqin, 18:58

0 Comments:

发表评论

订阅 博文评论 [Atom]

<< 主页