Results 1 to 24 of 24

Thread: Persistent Debug Print Window

Threaded View

  1. #8
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,296

    Re: Persistent Debug Print Window

    one more addition, just in case the vb process is running as admin

    Code:
    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
    and a sample C client

    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();
    
    }
    Last edited by dz32; Feb 22nd, 2022 at 10:40 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width