通过 DTM_SETSYSTEMTIME 更新另一个进程中的 dateTimePicker
我正在尝试使用 DTM_SETSYSTEMTIME 更新另一个应用程序中的 dateTimeController 。
bool retVal = false;
ushort GDT_VALID = 0;
SYSTEMTIME td = new SYSTEMTIME();
td.wYear = 1990;
td.wMonth = 4;
td.wDay = 2;
td.wDayOfWeek = 0;
td.wHour = 0;
td.wMilliseconds = 0;
td.wMinute = 0;
td.wSecond = 0;
int erc = SendMessage(handle, DTM_SETSYSTEMTIME, GDT_VALID, ref td);
不幸的是,尝试失败了,选择器没有更新,每次返回值都为零。 重要的是,在我执行 SendMessage 命令后,具有 dataTimePicker 的应用程序有时会给出非法内存访问异常的错误消息。
有人能帮我解决这个问题吗?
I am trying to update the dateTimeController in another application using DTM_SETSYSTEMTIME.
bool retVal = false;
ushort GDT_VALID = 0;
SYSTEMTIME td = new SYSTEMTIME();
td.wYear = 1990;
td.wMonth = 4;
td.wDay = 2;
td.wDayOfWeek = 0;
td.wHour = 0;
td.wMilliseconds = 0;
td.wMinute = 0;
td.wSecond = 0;
int erc = SendMessage(handle, DTM_SETSYSTEMTIME, GDT_VALID, ref td);
Unfortunately the attempt was failed, the picker is not updated, every time return value is zero.
Important thing is occasionally the application having the dataTimePicker gives an error message that illegal memory access exception after I execute the SendMessage command.
Can anybody help me to fix this up ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,无法工作。 SendMessage 的第四个参数是指向 SYSTEMTIME 的指针。该指针值仅在您的进程中有效,而不是在拥有该控件的进程中有效。使用该指针值使目标应用程序崩溃是很有可能的。您需要
这里可能会出现很多问题,首先是 UAC 阻止您执行这些高度特权的 API 函数。这个函数的名字很适合谷歌,你应该很容易找到示例代码。
Yes, cannot work. The 4th argument to SendMessage is a pointer to SYSTEMTIME. The pointer value is only valid in your process, not the one that owns the control. Crashing the target app with that pointer value is quite possible. You will need to
Lots of things that can go wrong here, starting with UAC stopping you from executing these highly privileged API functions. The function names google well, you should have little trouble finding sample code.
您的信息对我解决问题非常有帮助。以下是代码。
方法被调用,
Your information is really helpful for me to fix my issue. Following is the code.
Method is called by,