为什么我得到异常使用SendMessage时无法找到入口点?

时间:2017-07-09 22:59:05

标签: c# .net winforms

我正在尝试将一些文本发送到记事本窗口。

在form1的顶部:

const int WM_SETTEXT = 0X000C;

//include FindWindowEx
[DllImport("user32.dll")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

//include SendMessage
[DllImport("user32.dll")]
public static extern int SendMessages(IntPtr hWnd, int uMsg, int wParam, string lParam);

然后在构造函数中:

//getting notepad's process | at least one instance of notepad must be running
Process notepadProccess = Process.GetProcessesByName("notepad")[0];

//getting notepad's textbox handle from the main window's handle
//the textbox is called 'Edit'
IntPtr notepadTextbox = FindWindowEx(notepadProccess.MainWindowHandle, IntPtr.Zero, "Edit", null);
//sending the message to the textbox
SendMessages(notepadTextbox, WM_SETTEXT, 0, "This is the new Text!!!");

例外是在线:

SendMessages(notepadTextbox, WM_SETTEXT, 0, "This is the new Text!!!");

exe中出现未处理的“System.EntryPointNotFoundException”类型异常

其他信息:无法在DLL“user32.dll”中找到名为“SendMessages”的入口点。

完整的异常消息:

System.EntryPointNotFoundException was unhandled
  HResult=-2146233053
  Message=Unable to find an entry point named 'SendMessages' in DLL 'user32.dll'.
  Source=Grads_Scripts
  TypeName=""
  StackTrace:
       at Grads_Scripts.Form1.SendMessages(IntPtr hWnd, Int32 uMsg, Int32 wParam, String lParam)
       at Grads_Scripts.Form1..ctor() in D:\C-Sharp\Form1.cs:line 142
       at Grads_Scripts.Program.Main() in D:\C-Sharp\Program.cs:line 19
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

1 个答案:

答案 0 :(得分:2)

由于错误试图告诉你,没有这样的功能。

您的意思是SendMessage

相关问题