|
|
|
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
|
|