您的位置:程序门 -> 移动平台 -> windows mobile



调用外部函数 dllimport("sms.dll") smsgetphonenumber


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


调用外部函数 dllimport("sms.dll") smsgetphonenumber
发表于:2007-08-19 01:31:12 楼主
我通过调用外部函数   dllimport( "sms.dll ")   smsgetphonenumber获取本机号码,
编译没有问题,但是运行时报错如下。
can 't   find   pinvoke   dll   'sms.dll '.
提示为
如果类库中的某个方法已被移除或重命名,请重新编译引用该方法的所有程序集。  
此异常通常在试图动态访问未通过其强名称引用的程序集中已删除或重命名的方法时引发。

但是我查msdn   sms.dll   中有smsgetphonenumber函数。

程序如下:
[dllimport( "sms.dll ")]
                private   static   extern   intptr   smsgetphonenumber(intptr   psmsaaddress);

unsafe   public   static   phoneaddress   getphonenumber()
                {
                        phoneaddress   phoneaddr   =   new   phoneaddress();

                        byte[]   buffer   =   new   byte[516];
                        fixed   (byte*   paddr   =   buffer)
                        {
                                intptr   res   =   smsgetphonenumber((intptr)paddr);
                                if   (res   !=   intptr.zero)
                                        throw   new   exception( "could   not   get   phone   number   from   sim ");

                                byte*   pcurrent   =   paddr;
                                phoneaddr.addresstype   =   (addresstype)marshal.readint32((intptr)pcurrent);
                                pcurrent   +=   marshal.sizeof(phoneaddr.addresstype);
                                phoneaddr.address   =   marshal.ptrtostringuni((intptr)pcurrent);
                        }

                        return   phoneaddr;
                }
请问如何解决。
发表于:2007-08-19 11:12:331楼 得分:0
http://msdn2.microsoft.com/en-us/library/aa446543.aspx
发表于:2007-08-19 12:37:312楼 得分:0
我就是用的这个例子。
但是在执行函数   smsgetphonenumber获取本机号码的时候,
编译没有问题,但是运行时报错如下。
can 't   find   pinvoke   dll   'sms.dll '.
提示为
如果类库中的某个方法已被移除或重命名,请重新编译引用该方法的所有程序集。  
此异常通常在试图动态访问未通过其强名称引用的程序集中已删除或重命名的方法时引发。
发表于:2007-08-19 12:57:233楼 得分:0
看看smsgetphonenumber返回什么结果,现在的sim卡里一般都不存储电话号码。因此这个函数经常会失败


快速检索

最新资讯
热门点击