Quantcast
Channel: General Windows Desktop Development Issues forum
Viewing all 6180 articles
Browse latest View live

CryptoAPI not working in Windows 2008R2 Web service, it worked in WS 2003 web service

$
0
0

We have a web service running in a 32-bit Windows Server 2003 that uses the cryptoAPI to encrypt and decrypt strings.  When I install this same code web service on 64-bit WS2008R2 inside IIS 7.5, the encryption does not work.  It is only when in a web service environment that the encryption does not work on the WS 2008 R2 server.

The encryption works when calling the same cryptoAPIs when called from an desktop executable file.

Is there configuration that I need to do to allow a WS 2008R2 web service to call the CRYPTOAPI?

Do I need to change my cryptoAPI code when I switch from a 32-bit Windows Server to a 64-bit Windows Server?



Leaking memory when using NtQuerySystemInformation ()

$
0
0

I'm using NtQuerySystemInformation () as a method to frequently attach exe names to PIDs, as it seems to be both much faster and less resource intensive as other methods. (If I'm wrong, I'd be happy to go in a different direction.) I've noticed, though, that if I hammer this function repeatedly my usage of private memory and working set will (rather erratically) go up.

Anyway, I'm using the SystemProcessInformation parameter, which returns a SYSTEM_PROCESS_INFORMATION_DETAIL object, which then contains a UNICODE_STRING. This object then contains a pointer to the exe name. I'm not allocating memory for this pointer in my code, so it's being allocated in the function. The problem is that I have no idea how to free it when I'm done with it. I've tried both a simplistic free () call and a RtlFreeUnicodeString (), both of which crashed the program.

Anyone have any experience with this?

(anecdotally, I have noticed on occasion that if I leave my test program running for too long my (Windows 7) user interface breaks. My screen goes black, but I can still move my pointer around. Has happened three times so far when running this code. Have been forced to do a hard reboot.)

Thanks for any help you can provide.

How can I change an assigned COM port automatically?

$
0
0

Is there a way one could change an assigned COM port number via scripts or other automated function?

I ask based on this particular scenario:

Suppose COM6 is assigned for Bluetooth (virtual serial port) communication.  I pair a Bluetooth printer successfully and can print successfully over COM6 to the Bluetooth printer.

If I pair a second printer, a new COM port number is assigned to that printer (say COM7).

Is it possible to disassociate COM6 from the old printer and associate COM6 with the new printer in an automated way?

I am familiar with the Device Manager and manually changing COM port numbers that way, but I'm looking for a way to automate this with batch scripts or something.

How to Reset "Windows firewall has blocked some features" Message?

$
0
0

My team is testing some new software applications on an extremely locked-down environment.  One of the new features causes the above message to be displayed when we run our application, but only once.  Thereafter, we don't see the message anymore.  Our assumption is that the blocking is still happening, but Windows Firewall is just not telling us, because it's already told us once.  Further, due to the high security settings, we don't have the option to "Allow Access".  There is only the "Cancel" button.

We are researching a way around this blocking, but this requires multiple tries.  Presently our only option is:

  • Create new Virtual Machine (VM)
  • Install our application software
  • Get the one-time message
  • Repeat

This sequence takes a long time, as the application install and setup itself is a 30-40 minute process.

So the question is:  How can we "reset" the message so we can get it to display again, without having to make a new VM and install our application each time?  Registry tweaks are acceptable.

Thanks...


Ron Mittelman

3rd party speech recognizer and Windows Speech Recognition

$
0
0

Hi

Is it possible to use Windows Speech Recognition tool with 3rd party SAPI speech recognizer.

Say, I have a SAPI SR engine for a language for which no Microsoft recognizer is available. Can I use it for dictation with Windows Speech Recognition tool?

InternetSetOption() Set INTERNET_OPTION_SETTINGS_CHANGED and INTERNET_OPTION_REFRESH *from a Worker Thread* has no effect.

$
0
0


My code alter the proxy settings and, after, calls this two InternetSetOptionfrom a worker-thread (no error occurs):

DWORD le = 0;

BOOL ok1 = InternetSetOption(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
        // Notifies the system that the registry settings have been changed
        // so that it verifies the settings on the next call to InternetConnect.

BOOL ok2 = InternetSetOption(NULL, INTERNET_OPTION_REFRESH , NULL, 0);
        // Causes the proxy data to be reread from the registry for a handle. 
        // No buffer is required.

if ((ok1==FALSE)||(ok2==FALSE))
        le = GetLastError();//For debug.


Expected results: The browser should reread the new settings.

Actual results: It doesn't.

*** Any idea why? ***

---

* When I call it from the main thread everything is fine.























NtSetInformationProcess and CPU Rate Limits on Server 2008 R2

$
0
0

Hi,

Page 478 of Windows Internals 6th edition (Part 1) talks about CPU rate limits and this method of implementing them;

"By calling NtSetInformationProcess and giving it the process handle of the process to limit and the CPU rate limiting information, if the process is tied to the system quota block."

I've been looking through all the NtSetInformation process info I can find in a web search but I can't see any data structures or attributes which deal with CPU quota's or rates.

Does anyone know of any way of implementing this? I'd guess that if it is mentioned in Windows Internals, it is at least possible.

Kind Regards

EMW

2709 -- offline join completion information was not found. on Windows 8.1

$
0
0

I have an app that has been running fine on users machines in xp,7, and 8.0

This weekend 3 users purchased new 8.1 machines and are unable to install my app.

The get the message "2709 -- offline join completion information was not found." then the installer stops.

I verified that all anti virus. malware process's are not running. I also verified the installer exe is working correctly by copying to an older machine and running the installer.

Any ideas would be appreciated.



What Does The "@" As The First Character Of The Font Name Signify?

$
0
0

Hi folks:

   When I enumerate face names to add to the face name combo box decorating a dialog for editing rich text, about 1/4 of the face names begin with "@". 

   What does this signify? 

   I'm trying to decide if these are face names the user should be able to select.

      Thanks
      Larry

TLS Problem on Win 8.1

$
0
0
Using Schannel, the following call works just fine on Windows Vista and Win 7, but not on Win 8.1.

CryptCreateHash(hCryptProv, CALG_SCHANNEL_MASTER_HASH, hMasterKey, 0, hMasterHash)

It returns Error 0x80090020 NTE_FAIL when using 128 bit RC4 & 160 bit SHA-1. When I enumerate the supported protocols, both are listed.

I have run out of ideas, and would appreciate any help.

J.A. Coutts

Finding Attributes of Selected Text In Rich Text Control?

$
0
0

Hello Folks:

   Developing on Win 8.1 Pro, VS 2010 Pro, C++, WIN32 no MFC. 

   Can I look at the attributes of each character the user selects in a rich text control? 

   I've built a function that allows a person to edit text in a rich text control. 

   Of course, I offer them the opportunity to change the typeface, font size, bold, italic, underline, foreground color and background text color. 

   Thanks to assistance from folks on this and the C++ forum, editing is working fine. 

   Is there a technique which allows me to see these attributes in the text the user highlights? 

   For example, I have a combo box that allows the user to select a type face.  I'd like this combo to reflect the typeface for the text the user has selected. 

   If the user highlights some text that uses the Arial typeface I'd like to see "Arial" as the selected item in the typeface combo box.  If the user select text that uses Arial and additional text that uses Courier, I'd like to have a blank entery selected in the combo box. 

   And I'd like to see this for all of the combo boxes that select a text's attributes,

   So, can I look at the attributes of each character the user selects?  I don't mind looking at each individual character. 

   Or is there a simpler solution to my problem?

      Thanks
      Larry





MFC dialogs scaling for Per monitor DPI aware application?

$
0
0

I have declared my application to be Per Monitor DPI Aware in the manifest file. There are quite a few MFC dialogs and all are defined in the rc file in dialog units. Can you clarify how I should handle the application response to WM_DPICHANGED message?

1. Should I update the size of the window(cdialog) using SetWindowPos with the size passed in LPARAM?

2. Should I scale the UI elements inside the dialog(the UI elements come from .rc and not created dynamically thro' code) or does MFC take care of scaling them?

Thanks,

Narayani

the using of CryptCATPutMemberInfo

$
0
0

CryptCATPutMemberInfo have a parameter: pwszReferenceTag

I find that if the _wcslen(pwszReferenceTag)> 64, then the function will return 0x57(error parameters). 

Then I use VS find the assamble code of this function:

761D2300   lea         edx,[eax+2]
761D2303   mov         cx,word ptr [eax]
761D2306   inc         eax
761D2307   inc         eax
761D2308   cmp         cx,di
761D230B   jne         761D2303
761D230D   sub         eax,edx
761D230F   push        40h
761D2311   sar         eax,1
761D2313   pop         esi
761D2314   cmp         eax,esi   ; here is compare lenth of the string with 0x40

But I found there's no files about the length of the string.

So is there anybody know the why? why _wcslen(pwszReferenceTag) <= 64?


WM_INPUT message no longer sent in Windows Technical Preview build 9879?

$
0
0

I had software that relied on the WM_INPUT message and it used to work with previous builds (and Win 8.1). I needed it for remapping a wireless keyboard's fn key to CTRL key (I was using an Autohotkey script which captures WM_INPUT).

But now looking at the messages sent when typing in the keyboard in a win32 app, only the button down and up are being sent. What changed? how to work around it?

Now I am using a hacky combination of user32.dll's SendInput and some methods from setupapi.dll to read/send the special key values.




Printing Rich Text Leaves Trailing White Space

$
0
0

Hello Folks:

   Developing in Win 8.1 Pro with Visual Studio 2010, WIN32, no MFC.   The application uses multi-byte code, not UNICODE. 

   I want to be able to print rich text inside an arbitrary rectangle. 

   The text will come from a database, and not be associated with any rich text control. 

   I believe the first step is to get the text printed to an arbitrary rectangle in an arbitrary HDC. 

   So the sample I'm presenting attempts to display on the dialog's HDC when the user presses the "OK" button.

   The code I've written to do this has a problem.  A white block is displayed to the right of any text I attempt to display:

   The top box is a rich text edit control, the bottom box is an arbitrary rectangle defined in the dialog's HDC after receiving the rich text. 

   I apologize for the amount of code that follows, but this will reproduce the problem, and might help you assist me:

      Header file trailing_white_line_problem.h:

#ifndef TRAILING_WHITE_LINE_PROBLEM_H
#define TRAILING_WHITE_LINE_PROBLEM_H

#define DEFAULT_RICHEDIT_CLASS MSFTEDIT_CLASS

const int TWIPS_TO_POINTS = 20;
const COLORREF BACKGROUND_COLOR = RGB(0xD0, 0xD0, 0xD0);
const COLORREF FOREGROUND_COLOR = RGB(0x00, 0x00, 0x00);

bool text_has_a_graphic_char(const std::string *test_string_ptr);

bool text_has_a_graphic_char(const char *test_text);

void copy_rtf_to_hdc(HWND hdlg);

void setup_dialog(HWND hdlg);

INT_PTR CALLBACK trailing_white_dialog_box(HWND hdlg,
                                                UINT message,
                                                    WPARAM wParam,
                                                        LPARAM lParam);

void rtf_to_hdc(HDC dest_hdc, std::string *rtf_string_ptr, RECT *destination_rect_ptr,
                                                            COLORREF background_color);

class RICH_TEXT_STREAM_STRING_REC
{
public:

    RICH_TEXT_STREAM_STRING_REC(std::string *string_ptr_arg):
                                string_ptr(string_ptr_arg),
                                position(0)
    {
    }

    RICH_TEXT_STREAM_STRING_REC(HWND rich_text_control_arg,
                                std::string *string_ptr_arg):
                                rich_text_control(rich_text_control_arg),
                                string_ptr(string_ptr_arg),
                                position(0)
    {
    }
    void increment_position(LONG increment_arg)
    {
        if (this != NULL)
        {
            position += increment_arg;
        }
    }

    void read(std::string *input_string_ptr)
    {
        EDITSTREAM edit_stream_struct;

        if(this != NULL)
        {
            if(rich_text_control != NULL)
            {
                memset(&edit_stream_struct, 0x00, sizeof edit_stream_struct);

                position = 0;

                string_ptr = input_string_ptr;

                if(string_ptr != NULL)
                {
                    string_ptr->erase();
                    // edit_stream_struct.pfnCallback = rich_text_control_stream_write_callback;

                    edit_stream_struct.dwCookie = DWORD_PTR(this);
                    edit_stream_struct.pfnCallback =
                            &RICH_TEXT_STREAM_STRING_REC::rich_text_control_stream_read_callback;

                    SendMessage(rich_text_control, EM_STREAMOUT, SF_RTF, LPARAM(&edit_stream_struct));
                }
            }
        }
    }


    void write(HWND rich_text_control)
    {
        EDITSTREAM edit_stream_struct;

        if(this != NULL)
        {
            memset(&edit_stream_struct, 0x00, sizeof edit_stream_struct);

            position = 0;

            if(string_ptr != NULL)
            {
                // edit_stream_struct.pfnCallback = rich_text_control_stream_write_callback;

                edit_stream_struct.dwCookie = DWORD_PTR(this);
                edit_stream_struct.pfnCallback =
                &RICH_TEXT_STREAM_STRING_REC::rich_text_control_stream_write_callback;

                SendMessage(rich_text_control, EM_STREAMIN, SF_RTF, LPARAM(&edit_stream_struct));
            }
        }
    }

    static DWORD CALLBACK rich_text_control_stream_read_callback(DWORD_PTR dwCookie,
                                                                    LPBYTE pbBuff,
                                                                    LONG cb,
                                                                    LONG *pcb)
    {
        DWORD return_val = 0;	// Zero indicates success.
        RICH_TEXT_STREAM_STRING_REC *stream_rec_ptr = (RICH_TEXT_STREAM_STRING_REC *)dwCookie;
        std::string *local_string_ptr = stream_rec_ptr->string_ptr;

        if(stream_rec_ptr != NULL)
        {
            local_string_ptr->append((const char *)pbBuff, cb);
            stream_rec_ptr->increment_position(cb);

            if(*pcb != NULL)
            {
                *pcb = cb;
            }
        }

        return return_val;
    }

    // Make this function static, to allow assignment to a pointer.
    static DWORD CALLBACK rich_text_control_stream_write_callback(DWORD_PTR dwCookie,
                                                                    LPBYTE pbBuff,
                                                                    LONG cb,
                                                                    LONG *pcb)
    {
        DWORD return_val = 0;	// Zero indicates success.
        RICH_TEXT_STREAM_STRING_REC *stream_rec_ptr = (RICH_TEXT_STREAM_STRING_REC *)dwCookie;
        std::string *local_string_ptr = stream_rec_ptr->string_ptr;
        int local_position = stream_rec_ptr->position;
        int char_to_write_count = 0;

        if(stream_rec_ptr != NULL)
        {
            char_to_write_count = std::min(int(local_string_ptr->size() - local_position), int(cb));

            strncpy((char*)pbBuff,
                    local_string_ptr->substr(local_position, char_to_write_count).c_str(),
                                                                    char_to_write_count);

            stream_rec_ptr->increment_position(char_to_write_count);

            if(*pcb != NULL)
            {
                *pcb = char_to_write_count;
            }
        }

        return return_val;
    }

private:

    std::string *string_ptr;
    HWND rich_text_control;
    LONG position;

};
#endif

   Here is the C++ file:

#define NOMINMAX
#include <windows.h>
#include <Windowsx.h>
#include <Richedit.h>
#include "resource.h"

#include <iostream>
#include <string>
#include <algorithm>

#include "trailing_white_line_problem.h"

int WINAPI WinMain (HINSTANCE hinstance, HINSTANCE hPrevInstance,
                                            PSTR szCmdLine, int iCmdShow)
{
    DWORD error_code = 0;

    LoadLibrary(TEXT("Msftedit.dll"));

    SetLastError(0);

    INT_PTR dialogbox_return = DialogBox(hinstance,
                                            "IDD_SOURCE_RTF_DIALOG", NULL,
                                                (DLGPROC)trailing_white_dialog_box);

    if(dialogbox_return != 0)
    {
        error_code = GetLastError();
    }
}

INT_PTR CALLBACK trailing_white_dialog_box(HWND hdlg,
                                                UINT message,
                                                    WPARAM wParam,
                                                        LPARAM lParam)
{
    int test_x = 0;

    switch (message)
    {
    case WM_INITDIALOG:

        setup_dialog(hdlg);

        return 0;

    case WM_COMMAND:

        switch(LOWORD (wParam))
        {

        case IDOK:

            copy_rtf_to_hdc(hdlg);

            return 0;

        case IDCANCEL:		// Needed for upper right "X" to function.

            switch(HIWORD(wParam))
            {
            case BN_CLICKED:
                SetLastError(0);
                EndDialog(hdlg, true);
                break;
            }

            return 0;
        }
    }

    return 0;
}

void setup_dialog(HWND hdlg)
{
    HWND edit_box_handle = GetDlgItem(hdlg, IDC_RTF_EDIT);
    CHARFORMAT2 charformat_record;

    memset(&charformat_record, 0x00, sizeof charformat_record);
    charformat_record.cbSize = sizeof charformat_record;

    LPARAM rich_text_edit_event_mask = ENM_CHANGE |
                                        ENM_UPDATE |
                                        ENM_SCROLL |
                                        ENM_DRAGDROPDONE |
                                        ENM_PARAGRAPHEXPANDED |
                                        ENM_PAGECHANGE |
                                        ENM_KEYEVENTS |
                                        ENM_REQUESTRESIZE |
                                        ENM_SELCHANGE |
                                        ENM_DROPFILES |
                                        ENM_PROTECTED |
                                        ENM_CORRECTTEXT |
                                        ENM_IMECHANGE |
                                        ENM_LANGCHANGE |
                                        ENM_OBJECTPOSITIONS |
                                        ENM_LINK |
                                        ENM_LOWFIRTF;

    SendMessage(edit_box_handle, EM_SETBKGNDCOLOR, 0, BACKGROUND_COLOR);

    // Enable the edit control to send notifications to parent dialog.
    SendMessage(edit_box_handle, EM_SETEVENTMASK, 0, rich_text_edit_event_mask);

    SendMessage(edit_box_handle, EM_SETBKGNDCOLOR, 0, BACKGROUND_COLOR);

    // Enable the edit control to send notifications to parent dialog.
    SendMessage(edit_box_handle, EM_SETEVENTMASK, 0, rich_text_edit_event_mask);

    // From setup_coach_observation_char_format:
    charformat_record.dwMask = CFM_ALL2;
    charformat_record.yHeight = 10 * TWIPS_TO_POINTS;
    charformat_record.crBackColor = BACKGROUND_COLOR;
    charformat_record.crTextColor = FOREGROUND_COLOR;

    SendMessage(edit_box_handle, EM_SETCHARFORMAT, SCF_ALL, LPARAM(&charformat_record));
}

void copy_rtf_to_hdc(HWND hdlg)
{
    RECT rich_text_rect;
    RECT button_rect;
    std::string rtf_string;
    HWND control_handle = GetDlgItem(hdlg, IDC_RTF_EDIT);;
    RICH_TEXT_STREAM_STRING_REC stream_rec(control_handle, &rtf_string);
    TEXTMETRIC tm;
    HDC hdc = GetDC(hdlg);;
    static int char_height;
    int display_rect_height = 0;

    if(char_height == 0)
    {
        GetTextMetrics(hdc, &tm);
        char_height = tm.tmHeight;
    }

    // Define the rectangle that will receive the rich text.
    // Make this the same width as the edit rectangle, and
    // fit it between the edit rectangle and the "OK" button.
    // control_handle = GetDlgItem(hdlg, IDC_RTF_EDIT);
    GetWindowRect(control_handle, &rich_text_rect);

    control_handle = GetDlgItem(hdlg, IDOK);
    GetWindowRect(control_handle, &button_rect);

    display_rect_height =
                    (button_rect.top - rich_text_rect.bottom) - char_height;

    MapWindowRect(NULL, hdlg, &rich_text_rect);

    // Move the rect.
    rich_text_rect.top = rich_text_rect.bottom + (char_height >> 1);
    rich_text_rect.bottom = rich_text_rect.top + display_rect_height;

    stream_rec.read(&rtf_string);

    rtf_to_hdc(hdc, &rtf_string, &rich_text_rect, BACKGROUND_COLOR);

    ReleaseDC(hdlg, hdc);
}

void rtf_to_hdc(HDC dest_hdc, std::string *rtf_string_ptr, RECT *destination_rect_ptr,
                                                            COLORREF background_color)
{
    HWND hdc_window = WindowFromDC(dest_hdc);
    HINSTANCE hinstance = HINSTANCE(GetWindowLongPtr(hdc_window, GWLP_HINSTANCE));
    HWND invisible_rich_text_control = NULL;
    int cxPhys = GetDeviceCaps(dest_hdc, PHYSICALWIDTH);
    int cyPhys = GetDeviceCaps(dest_hdc, PHYSICALHEIGHT);
    int invisible_control_width = 0;
    int invisible_control_height = 0;
    FORMATRANGE format_range;
    double pixels_to_twips_x = 0.0;
    double pixels_to_twips_y = 0.0;
    RICH_TEXT_STREAM_STRING_REC stream_rec(rtf_string_ptr);
    HFONT current_font = HFONT(GetCurrentObject(dest_hdc, OBJ_FONT));

    HDC invisible_control_hdc = NULL;
    RECT invisible_control_rect;
    HBRUSH background_brush = CreateSolidBrush(background_color);

    SelectObject(dest_hdc, background_brush);

    if((cxPhys == 0) || (cyPhys == 0))
    {
        // PHYSICALWIDTH and PHYSICALHEIGHT arguments are for printing devices.
        cxPhys = GetDeviceCaps(dest_hdc, HORZRES);
        cyPhys = GetDeviceCaps(dest_hdc, VERTRES);
    }

    if(text_has_a_graphic_char(rtf_string_ptr) && (dest_hdc != NULL) && (destination_rect_ptr != NULL))
    {
        invisible_control_width = destination_rect_ptr->right - destination_rect_ptr->left;
        invisible_control_height = destination_rect_ptr->bottom - destination_rect_ptr->top;

        if((invisible_control_width > 0) && (invisible_control_height > 0))
        {
            memset(&format_range, 0x00, sizeof format_range);
            format_range.hdc       = dest_hdc;
            format_range.hdcTarget = dest_hdc;

            // Set page rect to physical page size in twips.
            format_range.rcPage.top    = 0;
            format_range.rcPage.left   = 0;
            format_range.rcPage.right  = MulDiv(cxPhys, 1440, GetDeviceCaps(dest_hdc, LOGPIXELSX));
            format_range.rcPage.bottom = MulDiv(cyPhys, 1440, GetDeviceCaps(dest_hdc, LOGPIXELSY));

            // Set the rendering rectangle to the pintable area of the page.

            format_range.rc = format_range.rcPage;

            // This is going to be a bit clumsy until I understand what's going on.
            // I'm going to caculate the multiplier to convert pixels to twips.
            pixels_to_twips_x = double(format_range.rcPage.right) / double(cxPhys);
            pixels_to_twips_y = double(format_range.rcPage.bottom) / double(cyPhys);

            format_range.rc.left = MulDiv(destination_rect_ptr->left, 1440, GetDeviceCaps(dest_hdc, LOGPIXELSX));
            format_range.rc.top = MulDiv(destination_rect_ptr->top, 1440, GetDeviceCaps(dest_hdc, LOGPIXELSY));
            format_range.rc.right = MulDiv(destination_rect_ptr->right, 1440, GetDeviceCaps(dest_hdc, LOGPIXELSX));
            format_range.rc.bottom = MulDiv(destination_rect_ptr->bottom, 1440, GetDeviceCaps(dest_hdc, LOGPIXELSY));

            invisible_rich_text_control = CreateWindowExW(0,
                                                            DEFAULT_RICHEDIT_CLASS,
                                                            L"",
                                                            ES_MULTILINE |
                                                            ES_READONLY,
                                                            destination_rect_ptr->left,
                                                            destination_rect_ptr->top,
                                                            invisible_control_width,
                                                            invisible_control_height,
                                                            NULL, // hdlg,
                                                            NULL, // Menu
                                                            hinstance,
                                                            0);

            // The invisible conrol has the same width as the destination rectangle.
            SendMessage(invisible_rich_text_control, EM_SETTARGETDEVICE, (WPARAM)dest_hdc,
                                                                    invisible_control_width);

            invisible_control_rect.left = destination_rect_ptr->left;
            invisible_control_rect.top = destination_rect_ptr->top;
            invisible_control_rect.right = destination_rect_ptr->left + invisible_control_width;
            invisible_control_rect.bottom = destination_rect_ptr->top + invisible_control_height;

            // This is new code to try to force the background color.
            invisible_control_hdc = GetDC(invisible_rich_text_control);
            SetBkMode(invisible_control_hdc, TRANSPARENT);

            ReleaseDC(invisible_rich_text_control, invisible_control_hdc);

            stream_rec.write(invisible_rich_text_control);

            // Select the entire contents.
            SendMessage(invisible_rich_text_control, EM_SETSEL, 0, (LPARAM)-1);

            // Get the selection into a CHARRANGE.
            SendMessage(invisible_rich_text_control, EM_EXGETSEL, 0, (LPARAM)&format_range.chrg);

            FillRect(dest_hdc, destination_rect_ptr, background_brush);

            int cpMin = SendMessage(invisible_rich_text_control, EM_FORMATRANGE, TRUE, (LPARAM)&format_range);

            if (cpMin <= format_range.chrg.cpMin)
            {
                // fSuccess = FALSE;
            }

            // This must be called to prevent a memory leak.
            SendMessage(invisible_rich_text_control, EM_FORMATRANGE, FALSE, 0);

            DeleteObject(background_brush);

            DestroyWindow(invisible_rich_text_control);

            // Restore the HDC's font.
            SelectObject(dest_hdc, current_font);
        }
    }
}

bool text_has_a_graphic_char(const std::string *test_string_ptr)
{
    bool return_val = false;

    if(test_string_ptr != NULL)
    {
        return_val = text_has_a_graphic_char(test_string_ptr->c_str());
    }

    return return_val;
}

bool text_has_a_graphic_char(const char *test_text)
{
    bool graphic_char_found = false;
    int index = 0;
    int text_length = 0;

    if(test_text != NULL)
    {
        text_length = (int)strlen(test_text);

        while((index < text_length) && !graphic_char_found)
        {
            graphic_char_found |= (isascii(test_text[index]) && (isgraph(test_text[index]) != 0));++index;
        }
    }

    return graphic_char_found;
}

   Here is the .rc file

// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (United States) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE
BEGIN
    "resource.h\0"
END

2 TEXTINCLUDE
BEGIN
    "#include ""afxres.h""\r\n""\0"
END

3 TEXTINCLUDE
BEGIN
    "\r\n""\0"
END

#endif    // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//

IDD_SOURCE_RTF_DIALOG DIALOGEX 0, 0, 314, 271
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,205,250,50,14
    PUSHBUTTON      "Cancel",IDCANCEL,257,250,50,14
    CONTROL         "Here is some sample\r\ntext",IDC_RTF_EDIT,"RICHEDIT50W",WS_VSCROLL | 0x9144,7,7,300,116
END


/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//

#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
    "IDD_SOURCE_RTF_DIALOG", DIALOG
    BEGIN
        LEFTMARGIN, 7
        RIGHTMARGIN, 307
        TOPMARGIN, 7
        BOTTOMMARGIN, 264
    END
END
#endif    // APSTUDIO_INVOKED

#endif    // English (United States) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED

   I'm sorry to dump almost 500 lines of C++ on you, and I understand if nobody responds.  But this is actually the smallest I was able to distill the code that demonstrates the problem. 

   In addition to just getting this code to work, if you see other faults with this code, or ways that it can be made more efficient, please let me know. 

   Thanks to anybody who decides to help me. 

      Larry





How to get the realtime content of cmd?

$
0
0

Hello,

I want to get the cmd window content in realtime from a command line (Dism.exe /Online /Cleanup-Image /AnalyzeComponentStore) in Windows 8 or 8.1

http://www.eightforums.com/tutorials/44348-winsxs-folder-component-store-analyze-windows-8-1-a.html

My code is below, but i can not get the progress percent values in realtime into the textbox, why?

Note: Need to untick the "Primarily 32bit" in the project compiling options in 64bit OS.

//////////////////////////////////////////////////////////////////////////////////////////

 Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
        BackgroundWorker1.RunWorkerAsync()
    End Sub

    Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        Dim p As New Process
        p.StartInfo.UseShellExecute = False
        p.StartInfo.RedirectStandardOutput = True
        p.StartInfo.RedirectStandardError = True
        p.StartInfo.CreateNoWindow = True

        p.StartInfo.FileName = System.Environment.SystemDirectory & "\cmd.exe"
        p.StartInfo.Arguments = "/c Dism /Online /Cleanup-Image /AnalyzeComponentStore"

        AddHandler p.OutputDataReceived, AddressOf Process_OutputDataReceived

        p.Start()
        p.BeginOutputReadLine()
        p.WaitForExit()
        p.Close()
    End Sub

    Private Sub Process_OutputDataReceived(ByVal sender As Object, ByVal e As DataReceivedEventArgs)
        If txtResult.InvokeRequired Then
            txtResult.Invoke(New DataReceivedEventHandler(AddressOf Process_OutputDataReceived), sender, e)
        Else
            txtResult.Text += String.Format("{0}{1}", e.Data, Environment.NewLine)
        End If
    End Sub


wireshark capture the NFC packet

$
0
0

I built the wireshark source code on Windows plantform, and I download the wireshark-nfc source code and built it on win8 plantform. Then, I put the dll file into wireshark-1.6.11\wireshark-gtk2/plugins and run the wireshark.exe, I want to capture the NFC packet, I don't known which interface should I seclect?  What should I do to capture the NFC packet ? 

Windows Application with Office 365 support

$
0
0

Hi,

   I am a full fledged .NET web application developer, currently I got a requirement to build a .NET windows application

   with features like, 1) reading mails from a office 365 mailbox,  2) HTML5 type UI.

    I would like to learn an do this, can some one suggest some links or samples which would be a good start point form me.

Thank You,

Kalidhas.P

VSS Hardware Provider : Commit snapshot IN parameters

$
0
0

In vss hardware provider development, to create a snapshot 

CommitSnapshots(IN VSS_ID SnapshotSetId)

i have VSS_ID as IN , i need the page83 Data

rgLunInformation[0].m_deviceIdDescriptor.m_rgIdentifiers[0].m_rgbIdentifier (VDS_LUN_INFORMATION*)

How to get this information (which is available in AreLunSuported) in CommitSnapshots

Missing Background Color in HDC's RTF.

$
0
0

Hi Folks:

   Developing on Win 8.1, Visual Studio 2010, C++, WIN32, no MFC.

   I have a function that takes an std::string containing rich text and displays it in an HDC for a printer or a display. 

   Text is seems to be displayed, with one problem.  The part of the line following the text is always white:

   Here is the code of a function that places rich text from an std::string into a rectangle in an HDC:

void rtf_to_hdc(HDC dest_hdc, std::string *rtf_string_ptr, RECT *destination_rect_ptr)
{
    HWND hdc_window = WindowFromDC(dest_hdc);
    HINSTANCE hinstance = HINSTANCE(GetWindowLongPtr(hdc_window, GWLP_HINSTANCE));
    HWND invisible_rich_text_control = NULL;
    int cxPhys = GetDeviceCaps(dest_hdc, PHYSICALWIDTH);
    int cyPhys = GetDeviceCaps(dest_hdc, PHYSICALHEIGHT);
    int invisible_control_width = 0;
    int invisible_control_height = 0;
    FORMATRANGE format_range;
    double pixels_to_twips_x = 0.0;
    double pixels_to_twips_y = 0.0;
    RICH_TEXT_STREAM_STRING_REC stream_rec(rtf_string_ptr);
    HFONT current_font = HFONT(GetCurrentObject(dest_hdc, OBJ_FONT));

    HDC invisible_control_hdc = NULL;
    RECT invisible_control_rect;
    HBRUSH background_brush = CreateSolidBrush(RGB(0xFF, 00, 00));	// Red for testing

    if((cxPhys == 0) || (cyPhys == 0))
    {
        // PHYSICALWIDTH and PHYSICALHEIGHT arguments are for printing devices.
        cxPhys = GetDeviceCaps(dest_hdc, HORZRES);
        cyPhys = GetDeviceCaps(dest_hdc, VERTRES);
    }

    if(text_has_a_graphic_char(rtf_string_ptr) &&
                                        (dest_hdc != NULL) &&
                                                (destination_rect_ptr != NULL))
    {
        invisible_control_width =
                        destination_rect_ptr->right - destination_rect_ptr->left;

        invisible_control_height =
                        destination_rect_ptr->bottom - destination_rect_ptr->top;

        if((invisible_control_width > 0) && (invisible_control_height > 0))
        {
            memset(&format_range, 0x00, sizeof format_range);
            format_range.hdc       = dest_hdc;
            format_range.hdcTarget = dest_hdc;

            // Set page rect to physical page size in twips.
            format_range.rcPage.top    = 0;
            format_range.rcPage.left   = 0;

            format_range.rcPage.right  =
                        MulDiv(cxPhys, 1440, GetDeviceCaps(dest_hdc, LOGPIXELSX));

            format_range.rcPage.bottom =
                        MulDiv(cyPhys, 1440, GetDeviceCaps(dest_hdc, LOGPIXELSY));

            // Set the rendering rectangle to the pintable area of the page.

            format_range.rc = format_range.rcPage;

            // This is going to be a bit clumsy until I understand what's going on.
            // I'm going to caculate the multiplier to convert pixels to twips.
            pixels_to_twips_x = double(format_range.rcPage.right) / double(cxPhys);
            pixels_to_twips_y = double(format_range.rcPage.bottom) / double(cyPhys);

            format_range.rc.left =
                    MulDiv(destination_rect_ptr->left, 1440,
                                                GetDeviceCaps(dest_hdc, LOGPIXELSX));

            format_range.rc.top =
                    MulDiv(destination_rect_ptr->top, 1440,
                                                GetDeviceCaps(dest_hdc, LOGPIXELSY));

            format_range.rc.right =
                    MulDiv(destination_rect_ptr->right, 1440,
                                                GetDeviceCaps(dest_hdc, LOGPIXELSX));
            format_range.rc.bottom =
                    MulDiv(destination_rect_ptr->bottom, 1440,
                                                GetDeviceCaps(dest_hdc, LOGPIXELSY));

            invisible_rich_text_control = CreateWindowExW(0,
                                                            DEFAULT_RICHEDIT_CLASS,
                                                            L"",
                                                            ES_MULTILINE |
                                                            // WS_VISIBLE |
                                                            // WS_CHILD |
                                                            ES_READONLY,
                                                            // | WS_BORDER,
                                                            destination_rect_ptr->left,
                                                            destination_rect_ptr->top,
                                                            invisible_control_width,
                                                            invisible_control_height,
                                                            NULL, // hdlg,
                                                            NULL, // Menu
                                                            hinstance,
                                                            0);

            // The invisible conrol has the same width as the destination rectangle.
            SendMessage(invisible_rich_text_control, EM_SETTARGETDEVICE,
                                            (WPARAM)dest_hdc, invisible_control_width);

            invisible_control_rect.left = destination_rect_ptr->left;
            invisible_control_rect.top = destination_rect_ptr->top;

            invisible_control_rect.right =
                                destination_rect_ptr->left + invisible_control_width;

            invisible_control_rect.bottom =
                                destination_rect_ptr->top + invisible_control_height;

            // This is new code to try to force the background color.
            invisible_control_hdc = GetDC(invisible_rich_text_control);
            FillRect(invisible_control_hdc, &invisible_control_rect, background_brush);
            ReleaseDC(invisible_rich_text_control, invisible_control_hdc);

            stream_rec.write(invisible_rich_text_control);

            // Select the entire contents.
            SendMessage(invisible_rich_text_control, EM_SETSEL, 0, (LPARAM)-1);

            // Get the selection into a CHARRANGE.
            SendMessage(invisible_rich_text_control, EM_EXGETSEL, 0,
                                                            (LPARAM)&format_range.chrg);

            int cpMin = SendMessage(invisible_rich_text_control, EM_FORMATRANGE, TRUE,
                                                                (LPARAM)&format_range);

            if (cpMin <= format_range.chrg.cpMin)
            {
                // fSuccess = FALSE;
            }

            // This must be called to prevent a memory leak.
            SendMessage(invisible_rich_text_control, EM_FORMATRANGE, FALSE, 0);

            DestroyWindow(invisible_rich_text_control);

            // Restore the HDC's font.
            SelectObject(dest_hdc, current_font);
        }
    }
}

   RICH_TEXT_STREAM_STRING_REC.write() sends text to the rich text control with an EM_STREAMIN message. 

   I've recently added the FillRect() and SetBkColor() calls to try to force a background color.  No luck.

   What am I doing wrong?

      Thanks
      Larry


Viewing all 6180 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>