one more addition, just in case the vb process is running as admin
and a sample C clientCode:Private Declare Function ChangeWindowMessageFilter Lib "user32" (ByVal msg As Long, ByVal flag As Long) As Long 'Vista+ Const WM_COPYDATA = &H4A Const WM_COPYGLOBALDATA = &H49 Public Function AllowCopyDataAcrossUIPI() Dim a, b, c Const MSGFLT_ADD = 1 'a = ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD) b = ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD) c = ChangeWindowMessageFilter(WM_COPYGLOBALDATA, MSGFLT_ADD) 'MsgBox a & " " & b & " " & c End Function
Code:#include <Windows.h> #include <stdio.h> #include <conio.h> void msg(char); void msgf(const char*, ...); bool Warned=false; HWND hServer=0; HWND regFindWindow(void){ // SaveSetting "dbgWindow", "settings", "hwnd", Me.hWnd char* baseKey = "Software\\VB and VBA Program Settings\\dbgWindow\\settings"; char tmp[20] = {0}; unsigned long l = sizeof(tmp); HWND ret=0; HKEY h; printf("regFindWindow triggered\n"); RegOpenKeyExA(HKEY_CURRENT_USER, baseKey, 0, KEY_READ, &h); RegQueryValueExA(h, "hwnd", 0,0, (unsigned char*)tmp, &l); RegCloseKey(h); ret = (HWND)atoi(tmp); if(!IsWindow(ret)) ret = 0; return ret; } void FindVBWindow(){ char *vbIDEClassName = "ThunderFormDC" ; char *vbEXEClassName = "ThunderRT6FormDC" ; char *vbEXEClassName2 = "ThunderRT6Form" ; char *vbWindowCaption = "Persistent Debug Print Window" ; hServer = FindWindowA( vbIDEClassName, vbWindowCaption ); if(hServer==0) hServer = FindWindowA( vbEXEClassName, vbWindowCaption ); if(hServer==0) hServer = FindWindowA( vbEXEClassName2, vbWindowCaption ); if(hServer==0) hServer = regFindWindow(); //if ide is running as admin if(hServer==0){ if(!Warned){ //MessageBox(0,"Could not find msg window","",0); printf("Could not find msg window\n"); Warned=true; } } else{ if(!Warned){ //first time we are being called we could do stuff here... printf("hServer = %x\n", hServer); Warned=true; } } } int msg(char *Buffer){ if(!IsWindow(hServer)) hServer=0; if(hServer==0) FindVBWindow(); COPYDATASTRUCT cpStructData; memset(&cpStructData,0, sizeof(struct tagCOPYDATASTRUCT )) ; //_snprintf(msgbuf, 0x1000, "%x,%x,%s", myPID, GetCurrentThreadId(), Buffer); cpStructData.dwData = 3; cpStructData.cbData = strlen(Buffer) ; cpStructData.lpData = (void*)Buffer; int ret = SendMessage(hServer, WM_COPYDATA, 0,(LPARAM)&cpStructData); return ret; //log ui can send us a response msg to trigger special reaction in ret } void msgf(const char *format, ...) { DWORD dwErr = GetLastError(); if(format){ char buf[1024]; va_list args; va_start(args,format); try{ _vsnprintf(buf,1024,format,args); msg(buf); } catch(...){} } SetLastError(dwErr); } void main(void){ msg("this is my test"); msgf("this is test %d", 2); getch(); }




Reply With Quote