webspy 0 Newbie Poster

I'm working on a .NET application that loads web pages using multiple WebBrowser controls. There are several threads and WebBrowser controls involved (this is a server application, and the WebBrowser is required for capturing the rendered image), each thread creating a WebBrowser control and running a message loop for it.

My question/issue is related to the WebBrowser control. Every time a web page is loaded, the (Windows) handle usage for the process increases. The WebBrowser controls are disposed when no longer needed, but for some reason the handle count doesn't seem to decrease. The application handle usage grows to more than 15000 in less than 10 minutes.

While checking with Sysinternals Process Explorer I noticed most of the handles seem to be Thread handles (on a multi core server). On a single core machine it also reports lots of Event handles.

Is the WebBrowser control known to be leaking handles ? And are there any methods to detect the cause of the handle leak ?

(I tried WinDbg, but haven't had much success due to not having any experience in using it. Memory/Performance profilers don't reveal any managed resource leaks.)

Thanks in advance.

webspy 0 Newbie Poster

Hello!

I have an application running on a Windows 2003 dedicated server that saves web pages as images. My problem is that after converting it to a Windows service, all images have a 8-bit color depth. While it was running as a console application all images came out properly. Is there a way to change (or force) the color depth of the user under which the service runs ?

Thanks in advance.

webspy 0 Newbie Poster

C++

#include <iostream>

int main()
{
    for(int i = 1; i <= 10; std::cout << i++);
    return 0;
}
#include <iostream>

int main()
{
    int i = 1;
    while(i <= 10 ? std::cout << i++: false);
    return 0;
}
webspy 0 Newbie Poster

Thanks. The problem was indead caused by PluginName and PluginAuthor not being allocated. I was expecting them to be allocated by the dll. They're now allocated by the application and the dll only has to fill them.

webspy 0 Newbie Poster

I've attached the whole source code (Code-Blocks project, both sources and binaries, plus a sample plugin included).

I'm still learning C++, but I didn't heard of C++ containers yet :rolleyes:. I just searched about them on the web and found out they're part of the Standard Template Library (heard of C++ templates, but know little about them). Could you please point me to some good C++ STL/Templates tutorials ?

Thanks for helping me.

webspy 0 Newbie Poster

I'm working on a plugin system for my application. The plugins are in the form of a dll loaded by my application using LoadLibraryEx . I store information about each plugin in an arrray of structs:

typedef struct _InternalPluginInfo
{
    UINT ID;
    HMODULE Module;
    int Flags;
    PluginInfo Info;

} InternalPluginInfo;

But when I try to remove a plugin from the array with the following function I get a "memory could not be read" error from Windows. When there is only 1 plugin in the array, it works. When there are 2, it fails with that error. When there are 3 or more it seems to work also (altought if there are a lot of plugins it fails again).

int PluginManager::RemovePlugin(UINT ID)
{
    err = 0;
    UINT index = FindPlugin(ID);
    if(err == 0)
    {
        UINT k = 0;
        InternalPluginInfo* temp = new InternalPluginInfo[Count - 1];
        if(!temp)
        {
            err = 2;
            return FAILURE;
        }

        for(UINT i = 0; i < Count; i++)
        {
            if(Plugin[i].ID != ID)
            {
                temp[k].ID = Plugin[i].ID;
                temp[k].Flags = Plugin[i].Flags;
                temp[k].Module = Plugin[i].Module;
                temp[k].Info = Plugin[i].Info;
                k++;
            }
        }

        if(Plugin[index].Info.PluginName)
            delete [] Plugin[index].Info.PluginName;
        if(Plugin[index].Info.PluginAuthor)
            delete [] Plugin[index].Info.PluginAuthor;

        if(Plugin[index].Info.Callback)
            (Plugin[index].Info.Callback)(cPluginQuit, 0, 0);

        FreeLibrary(Plugin[index].Module);

        delete [] Plugin;
        Plugin = temp;
        Count = k;

        return SUCCESS;
    }

    err = 1;
    return FAILURE;
}

I think the error occurs beacuse of this line temp[k].Module = Plugin[i].Module; , but I'm not sure. When I remove it from the code, everything seems to work fine.

Thanks in advance.

webspy 0 Newbie Poster

are you using MFC CListView class? or CListCtrl class? the InsertItem() method returns an integer that is the ID for that item. You can then call SetItemData() to connect the row number of your array to that item. Then when the user selects an item your program should call GetItemData() to retrieve the array row number.

I'm using the Win32 API. The ListView_InsertItem macro returns me a zero-based index of the newly inserted item, but I don't think I can change that after insertion. The LVITEM structure I have to supply has a lParam member documented as an application-defined value in MSDN, but they also say it's only used by a few messages.

webspy 0 Newbie Poster

I'm developing a simple address book application which displays it's entries in a listview control. The entries are loaded from a file and stored in a array. My problem is I can't find a way to link the listview with the array (assign each item in the listview an ID so I can find it in the array). I've read about virtual listviews at MSDN but I find it too difficult for me to implement in my application. Isn't there any other way to do this ? (I don't need sample code, just some ideas). Thanks.

webspy 0 Newbie Poster

@Wolfpack: Thanks. I coincidentally happen to read Charles Petzold's book, but I'm only at page 273 :cheesy:.

@Shiva_nan: I'm a beginner in Windows programming, so I don't think I can help you very much. I'll post the code I used to create the listview and tab controls you see in the screenshots, but I don't know how to work with them yet.

// Resources.rc
  CONTROL "",IDC_TAB,"SysTabControl32",WS_CHILD|WS_VISIBLE|WS_TABSTOP|TCS_FOCUSNEVER,233,53,189,208
  CONTROL "",IDC_LIST,"SysListView32",LVS_REPORT|WS_CHILD|WS_VISIBLE|WS_TABSTOP|LVS_SINGLESEL,4,68,224,208,WS_EX_CLIENTEDGE

// Main.cpp (dialog box's WndProc)
    LPTSTR column[] = {"First Name", "Last Name", "Nickname"};
    HWND List = GetDlgItem(hWnd, IDC_LIST);

    LVCOLUMN lvc;
    lvc.mask = LVCF_WIDTH | LVCF_TEXT;
    lvc.cx = 110;

    for(unsigned int i = 0; i < sizeof(column) / sizeof(column[0]); i++)
    {
        lvc.pszText = column[i];
        ListView_InsertColumn(List, i, (LPARAM)&lvc);
    }

    LPTSTR tab[] = {"Basic", "Home Address", "Work Address"};
    HWND wtab = GetDlgItem(hWnd, IDC_TAB);

    TCITEM tci;
    tci.mask = TCIF_TEXT;

    for(unsigned int i = 0; i < sizeof(tab)/sizeof(tab[0]); i++)
    {
        tci.pszText = tab[i];
        TabCtrl_InsertItem(wtab, i, &tci);
    }
webspy 0 Newbie Poster

I have the following script of a dialog box:

#include "Resources.h"
IDD_MAIN DIALOGEX 0,0,500,300
FONT 8,"Tahoma",400,0
STYLE WS_CAPTION|WS_VISIBLE|WS_SYSMENU|WS_GROUP|DS_CENTER
EXSTYLE WS_EX_APPWINDOW
BEGIN
    // controls
END
...
hDlgMain = CreateDialogParam(hInstance, 
  MAKEINTRESOURCE(IDD_MAIN), hWndMain, 
  MainDlgProc, (LPARAM)&MyData);
...

The dialog box itself works great, the problem is that it's not propely sized. As in the script, I want it 500 by 300 pixels, but for a reason I can't figure out, it's much bigger than that (it has around 800 by 600 pixels). I think it's something related with the font, cause when I lower the font's point size to 6, the whole dialog box becomes smaller (still not 500 by 300), but all the controls shrink as well.

I've attached some images. The third image appears normal, but I had to change the width and size to 426 and 281 so it appears at 645 by 489.

Can someone please tell me what I did wrong ? Thanks in advance.

webspy 0 Newbie Poster

Isn't .NET something similar with MFC, maybe it's succesor ? I rather make myself a simple Win32 wrapper to make apps faster, than using MFC or .NET. I know .NET has a lot of useful classes, but while I need only a few of them, why not develop them myself ?

webspy 0 Newbie Poster

I'm currently programming in C++ at an intermediate level and now moving on to the Win32 API. I know basic Win32 API programming so far and I don't find it too difficult to learn, but my question is: is it worth it to continue learning it while Windows Vista will be released in a short while and the .NET technology becomes more and more popular ? Since C# is similar to C++, should I switch to C# and learn the .NET framework ? Is .NET the future ? Thanks in advance.

webspy 0 Newbie Poster

I'm trying to make a simple game using the Windows GDI, so I'm developing some C++ classes to take care of window class registration, window creation, painting and other common tasks. So far I've finished the OBJECT class (which will be the base object from which the other classes such as BUTTON will derive), which holds a bitmap and paints it. The class works well so far, but I face a problem I can't find the solution. My windows stops updating (painting) itselfs after a while, even if it seems it gets the WM_PAINT message. Here's the code with which I test my class:

#include <windows.h>
#include "engine.h"

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

char szClassName[] = "Win32App";

char* Bitmaps[2] =     {    "C:\\Windows\\ACD Wallpaper.bmp",
                        "C:\\Windows\\Web\\Wallpaper\\Bliss.bmp"
                    };

OBJECT bmp;

HBITMAP Bitmap[2];
int BitmapCount = 2;

int i = 1, j = 0;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    LPTSTR CmdLine, int CmdShow)
{
    HWND hWnd;
    MSG msg;
    WNDCLASSEX wc;

    ZeroMemory(&wc, sizeof(wc));

    wc.hInstance = hInstance;
    wc.lpszClassName = szClassName;
    wc.lpfnWndProc = WndProc;
    wc.style = CS_DBLCLKS;
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_BACKGROUND;

    if(!RegisterClassEx(&wc))
        return 0;

    hWnd = CreateWindowEx(0, szClassName, "SampleApp", WS_OVERLAPPEDWINDOW,
                            CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL,
                            hInstance, NULL);

    Bitmap[0] = (HBITMAP)LoadImage(hInstance, Bitmaps[0], IMAGE_BITMAP,
                    1024, 768, LR_LOADFROMFILE);
    Bitmap[1] = (HBITMAP)LoadImage(hInstance, Bitmaps[1], IMAGE_BITMAP,
                    1024, 768, LR_LOADFROMFILE);

    ShowWindow(hWnd, SW_SHOWMAXIMIZED);
    UpdateWindow(hWnd);

    bmp.SetID(100);
    bmp.Create(Bitmap[0], 0, 0, 1024, 768, hWnd, NULL);
    bmp.Show();

    SetTimer(hWnd, 100, 1, NULL);

    while(GetMessage(&msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    char s[24];
    wsprintf(s, "painted %d times.", j);
    MessageBox(NULL, …