Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Windos
win32.3rdparty
win32.directx.audio
win32.directx.ddk
win32.directx.graphics
win32.directx.input
win32.directx.managed
win32.directx.misc
win32.directx.networking
win32.directx.sdk
win32.directx.video
win32.dirx.grap.shaders
win32.gdi
win32.international
win32.kernel
win32.messaging
win32.mmedia
win32.networks
win32.ole
win32.rtc
win32.tapi
win32.tapi.beta
win32.tools
win32.ui
win32.wince
win32.wmi
windows.mediacenter
winfx.aero
winfx.announcements
winfx.avalon
winfx.collaboration
winfx.fundamentals
winfx.general
winfx.indigo
winfx.sdk
winfx.winfs
  
 
date: Sun, 29 Jun 2008 21:21:00 -0700,    group: microsoft.public.win32.programmer.ui        back       


EM_STREAMOUT: Unhandled exception in msftedit.dll (includes sample   
I'm just trying to stream out text.  This very simple sample streams the text 
out and then crashes.  I'm probably missing something really obvious but I 
can't see it.

#ifndef WIN32
#define WIN32
#endif

#ifndef _DEBUG
#define _DEBUG
#endif

#ifndef _WINDOWS
#define _WINDOWS
#endif

#ifndef _UNICODE
#define _UNICODE
#endif

#ifndef UNICODE
#define UNICODE
#endif

#include <windows.h>
#include <Richedit.h>

// Global Variables:
HINSTANCE hInst;								// current instance
WCHAR szTitle[] = TEXT("Title");					// The title bar text
WCHAR szWindowClass[] = TEXT("WindowClass");			// the main window class name

// Forward declarations of functions included in this code module:
ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK	About(HWND, UINT, WPARAM, LPARAM);

#define USE_MSFTEDIT_CLASS 0

int WINAPI WinMain(          HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow
)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

#if USE_MSFTEDIT_CLASS
    LoadLibrary(TEXT("Msftedit.dll"));
#else
    LoadLibrary(TEXT("Riched20.dll"));
#endif

	MSG msg;

	// Initialize global strings
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}

    // Main message loop:
	while (GetMessage(&msg, NULL, 0, 0))
	{
		if (!TranslateAccelerator(msg.hwnd, 0, &msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return (int) msg.wParam;
}



ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= 0;
	wcex.hCursor		= 0;
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= 0;
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= 0;

	return RegisterClassEx(&wcex);
}

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

HWND g_hwndEdit = 0;

DWORD EditStreamCallbackFileRead( 
    DWORD_PTR dwCookie,
    LPBYTE pbBuff,
    LONG cb,
    LONG *pcb
    )
{
    HANDLE hFile = (HANDLE)dwCookie;

    DWORD numberOfBytesRead = 0;
    if ( !ReadFile( hFile, pbBuff, cb, &numberOfBytesRead, 0 ) )
    {
        return 1;
    }
    *pcb = (LONG)numberOfBytesRead;

    return 0;
}

DWORD StreamToOutputDebugString( 
    DWORD_PTR dwCookie,
    LPBYTE pbBuff,
    LONG cb,
    LONG *pcb
    )
{
    char temp[2] = {0,0};
    for ( int i = 0; i < cb; i++ )
    {
        temp[0] = (char)pbBuff[i];
        OutputDebugStringA( temp );
    }
    *pcb = (LONG)cb;

    return 0;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM 
lParam)
{
	switch (message)
	{
	case WM_CREATE:
        {
#if USE_MSFTEDIT_CLASS
            g_hwndEdit = CreateWindowEx(0, MSFTEDIT_CLASS, TEXT("Test"),
                ES_MULTILINE | WS_VISIBLE | WS_CHILD | WS_BORDER | 
WS_TABSTOP, 
                5, 5, 800, 600, 
                hWnd, NULL, hInst, NULL);
#else
            g_hwndEdit = CreateWindowEx(0, RICHEDIT_CLASS, TEXT("Test"),
                ES_MULTILINE | WS_VISIBLE | WS_CHILD | WS_BORDER | 
WS_TABSTOP, 
                5, 5, 800, 600, 
                hWnd, NULL, hInst, NULL);
#endif
            if ( g_hwndEdit == 0 )
            {
                return -1;
            }

            EDITSTREAM editstream;
            editstream.dwCookie = 0;
            editstream.dwError = 0;
            editstream.pfnCallback = 
(EDITSTREAMCALLBACK)StreamToOutputDebugString;
            
SendMessage(g_hwndEdit,EM_STREAMOUT,(WPARAM)SF_RTF,(LPARAM)&editstream);
        }
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
date: Sun, 29 Jun 2008 21:21:00 -0700   author:   Vince Harron

Re: EM_STREAMOUT: Unhandled exception in msftedit.dll (includes sample   
Vince Harron wrote:
> I'm just trying to stream out text.  This very simple sample streams the text 
> out and then crashes.  I'm probably missing something really obvious but I 
> can't see it.

Well, MSFTEDIT_CLASS is a unicode window. It will happily take ansi as 
an input, but the output stream will be in unicode. I suspect your issue 
is that your output routines casts from LPBYTE to char.

-- 
Joel Lucsy
"The dinosaurs became extinct because they didn't have a space program." 
-- Larry Niven
date: Mon, 30 Jun 2008 11:43:14 -0400   author:   Joel Lucsy

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us