Click here to Skip to main content
15,867,937 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to implement a windowless rich text box, but the example I found is only C++.
Now I have completed most of the code with C#. The only problem is that the function CreateTextServices has BUG (Win10x64 is ok, Win7x86 is error):
C#
protected override void OnHandleCreated(EventArgs e)
{
	base.OnHandleCreated(e);
	try
	{
		IntPtr pUnk = IntPtr.Zero;
		if (WinAPI.CreateTextServices(IntPtr.Zero, this, out pUnk) < 0)
			throw new Win32Exception();

		//Guid iid = typeof(WinInterface.ITextServices).GUID;
		//Marshal.QueryInterface(pUnk, ref iid, out ppv);
		//services = (WinInterface.ITextServices)
		//    Marshal.GetTypedObjectForIUnknown(ppv, typeof(WinInterface.ITextServices));

	}
	finally
	{
		//Marshal.Release(pUnk);
	}
}
[DllImport(ExternDll.Msftedit, SetLastError = true, CharSet = CharSet.Auto)]
public static extern int CreateTextServices(
			IntPtr punkOuter,
			WinInterface.ITextHost pITextHost,
			out IntPtr ppUnk
			);

On win7x86 it always throws a FatalExecutionEngineError exception.
Can someone help me? Thank you

What I have tried:

I modified the function parameter values of the ITextHost, but they have no effect.
Posted
Comments
Richard MacCutchan 28-Mar-19 7:56am    
What target processor is this compiled for, x86 or x64?
Troy-Z 28-Mar-19 20:54pm    
Any CPU, I compiled on Win7 can not run, but the compiled exe can be placed on Win10.
Richard MacCutchan 29-Mar-19 4:29am    
There must be some other incompatibility between your application and Windows 7. Check the versions of the .NET framework, the correct libraries etc.
Troy-Z 29-Mar-19 6:51am    
I have interviewed on two Win7 computers. It seems that others have encountered this problem, but I have not seen how he finally solved it: https://www.codeproject.com/Messages/4517125/How-to-use-CreateTextServices- in-Csharp.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900