delphihero(阿蒙(C++)) 的说法是有道理的:GetModuleHandle:This function must be used carefully in a multithreaded application. There is no guarantee that the module handle remains valid between the time this function returns the handle and the time it is used. For example, a thread retrieves a module handle, but before it uses the handle, a second thread frees the module. If the system loads another module, it could reuse the module handle that was recently freed. Therefore, first thread would have a handle to a module different than the one intended.上文来自《MSDN》
Retrieves a handle to the application instance.
使用方法:
HINSTANCE hInstance = GetWindowLong (hwnd, GWL_HINSTANCE);
其中,hwnd为主窗口的句柄。
2、我没有搞清楚实际内存对 SendMessage() 有什么帮助
还请楼上不吝赐教。如果能让我弄明白而且正确,我情愿把我所有的可用分都给你。
For example, a thread retrieves a module handle, but before it uses the handle, a second thread frees the module. If the system loads another module, it could reuse the module handle that was recently freed. Therefore, first thread would have a handle to a module different than the one intended.上文来自《MSDN》
而一般跟其他进程通信,都是FindWindow().....那个句柄才能反映另一个进程窗口情况。才是可以SendMessage()的对象。
你的可用分有多少阿。我的1w6,注册4年了。再给我也没意见可以先改变控制台名字( 默认的含路径不好输入:( )然后FindWindow
SetConsoleTitle("hello");
HWND hwnd = FindWindow(NULL,"hello");
SendMessage(hwnd,WM_CLOSE,0,0);//关闭控制台,也可以在其他程序里面给这个句柄发消息
system("PAUSE"); //这个语句不会被执行
这个就是那个控制台程序窗口句柄。绝对不是0x40...
楼主意思也是找个窗口句柄吧
由hwnd转过去:HINSTANCE hInstance = (HINSTANCE) ::GetWindowLongPtr(hwnd,GWL_HINSTANCE);
日,我有没说我的是 application instance。 前面已经有了这个函数了,我不过补充个参数你的那个函数搞错了还拽个屁。csdn开了我就注册了。
强烈鄙视不懂乱写的人。
HINSTANCE ht= AfxGetInstanceHandle() ;
CString str;
str.Format("%d",ht);
AfxMessageBox(str);
HMODULE HMD = GetModuleHandle(NULL);
str.Format("%d",HMD);
AfxMessageBox(str);
HWND hwnd = AfxGetMainWnd()->m_hWnd;
str.Format("%d",hwnd);
AfxMessageBox(str);
long lg = GetWindowLong(hwnd,GWL_HINSTANCE);
str.Format("%d",lg);
AfxMessageBox(str);
其实都是400000为之开始,+ 一个固定偏移地址(大概是dos显示win32应用的)。
控制台程序就是400000开始的。它的句柄应该是控制台句柄。(我这么觉得,不认同我也没办法)
调用 GetModuleHandle()和GetWindowLong()是两个完全不同结果。
也没什么好争得,我说的控制台应用句柄。你的是程序模块加载地址。
或许控制台就没有应用程序句柄的说法。
别生气,俺不要你的可用分,只跟你比较一下嘛。至于技术能力在下不敢比较,早对这方面心灰意冷。女怕嫁错郎,男怕入错行。