Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Clr Profiler - difficulties with communications

Featured Replies

Posted

Clr Profiler - difficulties on communications - on tracing result result back from dll to main exe's listview.
I have an Visual Studio 2010 project, profiler.dll is made on C++, main exe interface is also made on C++.
I've set two environment variables:
Cor_Enable_Profiling=1
COR_PROFILER={DFEC737C-D0B1-4b86-A6FD-FDD998BEEB03}
and I start the process with CreateProcess
The problems comes that I can't log event information back to main exe interface - listview.
Profiler dll gets called inside traced process.

Already tried:
main exe:

    unsigned int wndHandle = (unsigned int)GetDlgItem(IDC_LIST1)->m_hWnd;

    char buffer[10];
    std::sprintf(buffer, "hWnd=%d", (unsigned int)GetDlgItem(IDC_LIST1)->m_hWnd);
    std::string m_hWnd_str(buffer);


    const DWORD buffSize = 65535;
    static char buffer[buffSize];
    if (GetEnvironmentVariableA("hWnd", buffer, buffSize))
    {
    clist_hwnd = (HWND)atoi(buffer);
 

void Profiler::InsertStringToList(char* strToAdd)
{

    
            LVITEM item;
            item.mask = LVIF_TEXT;
            item.pszText = _T("Column Text");
            item.iItem = 0;      // Item number
            item.iSubItem = 0;         // Sub item number (column number)
            ::SendMessageA(clist_hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);

...

}

InsertStringToList("string test")

It just crushes.
 

what kind of crash does it show

 

What kind of IPC are you using ?

I released the full code of my Tracer long time ago and I think you can use some parts of it to solve this.

I used WM_COPYDATA for IPC.

how do you send data from the .NET process being profiled to the Process of the Profiler receiving data and viewing it ?

you need something like one of those methods for IPC.

  • Author
1 hour ago, Kurapica said:

how do you send data from the .NET process being profiled to the Process of the Profiler receiving data and viewing it ?

you need something like one of those methods for IPC.

I previously posted some code , I was trying to send the message to windows handle - listview m_hWnd
pass the handle as Environment variable hWnd=%d
then receive environment variable and convert it back: clist_hwnd = (HWND)atoi(buffer);
then just send message to listview handle using SendMessageA apis
 

Quote

 

void Profiler::InsertStringToList(char* strToAdd)
{

    
            LVITEM item;
            item.mask = LVIF_TEXT;
            item.pszText = _T("Column Text");
            item.iItem = 0;      // Item number
            item.iSubItem = 0;         // Sub item number (column number)
            ::SendMessageA(clist_hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);

...

}

 

What is IPC? for what it stand for?
 

 

Edited by CodeExplorer

https://www.geeksforgeeks.org/inter-process-communication-ipc/

 

I am not sure if it is possible to send the WM_COPYDATA message to a child window inside the other process.

I suggest you send it to the HWND of the main window in the receiving process and use Microsoft Spy++ to debug and inspect what gets sent.

such topics need patience and some testing so be ready :)

LVM_INSERTITEM deals with a structure that contains lots of pointers. Those pointers must be valid pointers and point to valid data inside your GUI process (=profiler.exe). You can't just take a random structure from one process and expect it to magically appear inside another process. (See more https://comp.os.ms-windows.programmer.win32.narkive.com/R6rjEbET/pointer-to-data-in-postmessage-lparam#post3)

That's where IPC (Inter Process Communication) comes into play. There are plenty of options (https://learn.microsoft.com/en-us/windows/win32/ipc/interprocess-communications) but @Kurapica already gave you possibly the easiest solution.

  • Author

I've succeed on the communication part, now data is send to main exe.
The problem is with adding string to listview:

 

LRESULT CALLBACK WMCOPYWNDPROC(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
 
  LVITEM item;
  LPWM_DATASTRUCTURE lpMsg;
  if (uMsg == WM_COPYDATA) {
     lpMsg = (LPWM_DATASTRUCTURE)((COPYDATASTRUCT*)lParam)->lpData;

     lpMsg->Data[lpMsg->cbSize]='\0';  // mark the end of string

     switch(lpMsg->iMessage)
     {
        case    WM_DISPLAY_TEXT:
                //TPRINTF(_T("\n"));
                //TPRINTF(lpMsg->Data);
            //::MessageBoxA(NULL, lpMsg->Data, "Error!", MB_OK);
            if (CClrTracerMainDlg::clist_hwnd!=NULL)
            {
            item.mask = LVIF_TEXT;
            item.pszText =  (LPSTR)&lpMsg->Data;
            item.iItem = 0;      // Item number
            item.iSubItem = 0;         // Sub item number (column number)
            ::SendMessageA(CClrTracerMainDlg::clist_hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
            }

        break;

        case    WM_QUIT_SERVER:
                PostQuitMessage(0);
        break;
     }
     return 0;
  }        
  else
   return ::DefWindowProc(hwnd, uMsg, wParam, lParam);
}

 

I've initialized clist_hwnd like this:
    clist_hwnd = GetDlgItem(IDC_LIST1)->m_hWnd;
    DWORD myThreadID;
    HANDLE myHandle = ::CreateThread(0, 0, ServerThread, &clist_hwnd, 0, 0);

Problems comes on ::SendMessageA, program freezes, also noticed wrong value of iItem/mask/iSubItem and good value of item.pszText - how it is possible?
 

I think you should remove this "return 0;" in your WMCOPYWNDPROC

I checked my old Tracer GUI code and noticed this possible error in your code

image.png.ef3e9ad24fc5e50034c9120cb5200caf.png

  • 3 weeks later...
  • Author

I was trying something like on:

Solved the problem of communication - I've used an window with specific class name and not main window for that.
Now the problem is that profiled program stucks but not always only sometimes on random runs.
Anyone know what this could be?
Traced program:
https://workupload.com/file/hhAhNcy76EG

Profiler
https://workupload.com/file/r5MfVUStzKN

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.