首页 新闻 会员 周边

利用API的SendMessage函数给第三方系统发送消息赋值的问题

0
悬赏园豆:10 [已关闭问题] 关闭于 2016-11-10 08:10

C# winform项目中,利用API的SendMessage函数给第三方系统发送消息赋值时,在XP系统出来一个比较奇怪的问题:在"纳税人识别号"这行中多出一个值"集团股份有限公司",其实应该不需要的。在XP系统中给第三方系统赋值如下:
名       称: 集团股份有限公司 
纳税人识别号: 91110612MA1M9AEW6B 集团股份有限公司
地址  、电话: 测试地址0522-68702111 
开户行及账号: 中国建设银行股份有限公司支行3201221212011280 

经测试,在WIN7或WIN2003 Server系统中利用API的SendMessage函数给第三方系统发送消息赋值时都正常,正确如下:
名       称: 集团股份有限公司 
纳税人识别号: 91110612MA1M9AEW6B
地址  、电话: 测试地址0522-68702111 
开户行及账号: 中国建设银行股份有限公司支行3201221212011280 

请各位帮忙看看,怎么样解决在XP系统中出现的问题,谢谢!

代码如下:

    [DllImport("User32.dll", EntryPoint = "SendMessage")]            public static extern int SendMessage(IntPtr hwnd, int msg, IntPtr wParam, string lParam);

    IntPtr hBuyer1 = API.FindWindowEx(hLookPanel, hSellAddressPhone, this.TARGET_CLASS_NAME, null);                                 IntPtr hBuyer2 = API.FindWindowEx(hLookPanel, hBuyer1, this.TARGET_CLASS_NAME, null);                                 IntPtr hBuyerBankAccount = API.FindWindowEx(hLookPanel, hBuyer2, this.TARGET_CLASS_NAME, null);                                 IntPtr hBuyBankAccountText = API.FindWindowEx(hBuyerBankAccount, IntPtr.Zero, this.TARGET_SUB_CLASS_NAME, null);   //开户行及账号                                 if (hBuyBankAccountText != IntPtr.Zero)                                 {                                     System.Threading.Thread.Sleep(10);                                     API.SendMessage(hBuyBankAccountText, API.WM_SETTEXT, IntPtr.Zero, "中国建设银行股份有限公司支行3201221212011280");                                                                  }

                                IntPtr hBuyerTaxpayerNumber = API.FindWindowEx(hLookPanel, hBuyerBankAccount, this.TARGET_CLASS_NAME, null);                                 IntPtr hBuyerTaxpayerNumberText = API.FindWindowEx(hBuyerTaxpayerNumber, IntPtr.Zero, this.TARGET_SUB_CLASS_NAME, null);   //纳税人识别号                                 if (hBuyerTaxpayerNumberText != IntPtr.Zero)                                 {                                     System.Threading.Thread.Sleep(10);                                     API.SendMessage(hBuyerTaxpayerNumberText, API.WM_SETTEXT, IntPtr.Zero, "91110612MA1M9AEW6B");                                                                    }                                                               

                                IntPtr hBuyerAddressPhone = API.FindWindowEx(hLookPanel, hBuyerTaxpayerNumber, this.TARGET_CLASS_NAME, null);                                 IntPtr hBuyerAddressPhoneText = API.FindWindowEx(hBuyerAddressPhone, IntPtr.Zero, this.TARGET_SUB_CLASS_NAME, null);   //地址、电话                                 if (hBuyerAddressPhoneText != IntPtr.Zero)                                 {                                     System.Threading.Thread.Sleep(10);                                     API.SendMessage(hBuyerAddressPhoneText, API.WM_SETTEXT, IntPtr.Zero, "测试地址0522-68702111");                                                                    }

                                IntPtr hBuyerOpeningName = API.FindWindowEx(hLookPanel, hBuyerAddressPhone, this.TARGET_CLASS_NAME, null);                                 IntPtr hBuyerOpeningNameText = API.FindWindowEx(hBuyerOpeningName, IntPtr.Zero, this.TARGET_SUB_CLASS_NAME, null);   //名称                                 if (hBuyerOpeningNameText != IntPtr.Zero)                                 {                                      System.Threading.Thread.Sleep(10);                                      API.SendMessage(hBuyerOpeningNameText, API.WM_SETTEXT, IntPtr.Zero, "集团股份有限公司");                                                                    }

 

lwr的主页 lwr | 初学一级 | 园豆:48
提问于:2016-11-08 10:57
< >
分享
所有回答(3)
0

还以为发一次...你一次次发测试不就行了

花飘水流兮 | 园豆:13560 (专家六级) | 2016-11-08 11:54
0

代码的用法是对的,既然出现问题是否是.net的版本的差异,可以尝试下如下的原始用法

[DllImport("USER32", EntryPoint = "SendMessage", CharSet = CharSet.Auto, SetLastError = true)] public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); IntPtr textPointer = Marshal.StringToCoTaskMemUni("Magic String"); SendMessage(handle, WM_SETTEXT, IntPtr.Zero, textPointer); Marshal.FreeCoTaskMem(textPointer);

http://stackoverflow.com/questions/19616445/automatic-casting-for-string-dllimport-arguments-vs-marshal-stringtocotaskmemuni/19616497?noredirect=1#comment29126007_19616497

2012 | 园豆:21230 (高人七级) | 2016-11-08 16:56
0

经测试,这主要是第三方系统的问题。谢谢各位回复。

lwr | 园豆:48 (初学一级) | 2016-11-10 08:09
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册