public override string ExtractString(SUIStringResource resourceToken) { IntPtr hInstance = IntPtr.Zero; IntPtr hModule = IntPtr.Zero; try { hInstance = SUIWinAPIs.LoadLibraryEx(resourceToken.ResourceDll, IntPtr.Zero, 2); if (resourceToken.StringID is int) { hModule = SUIWinAPIs.FindResource(hInstance, (int)resourceToken.StringID, (int)resourceToken.StringType); } else { hModule = SUIWinAPIs.FindResource(hInstance, (string)resourceToken.StringID, (int)resourceToken.StringType); } IntPtr hResData = SUIWinAPIs.LoadResource(hInstance, hModule); IntPtr ptr = SUIWinAPIs.LockResource(hResData); DialogTemplateEx dlgtemplateex = new DialogTemplateEx(); DialogTemplate dlgtemplate = new DialogTemplate(); Marshal.PtrToStructure(ptr, dlgtemplateex); Marshal.PtrToStructure(ptr, dlgtemplate); if ((dlgtemplateex.wSignature & 0xffff) == 0xffff) //if dlg is extend dlg { ptr = (IntPtr)(ptr.ToInt64() + Marshal.SizeOf(dlgtemplateex)); //directly operation memory address } else { ptr = (IntPtr)(ptr.ToInt64() + 0x12); } if (Marshal.ReadInt16(ptr) == -1) { ptr = (IntPtr)(ptr.ToInt64() + 4); } else { while (Marshal.ReadInt16(ptr) != 0) { ptr = (IntPtr)(ptr.ToInt64() + 2); } ptr = (IntPtr)(ptr.ToInt64() + 2); } if (Marshal.ReadInt16(ptr) == -1) { ptr = (IntPtr)(ptr.ToInt64() + 4); } else { while (Marshal.ReadInt16(ptr) != 0) { ptr = (IntPtr)(ptr.ToInt64() + 2); } ptr = (IntPtr)(ptr.ToInt64() + 2); } return(Marshal.PtrToStringAuto(ptr)); } catch (Exception e) { throw new SUIException("ExactString Error", e); } finally { if (!hInstance.Equals(IntPtr.Zero)) { SUIWinAPIs.FreeLibrary(hInstance); } } }
public override string ExtractString(SUIStringResource resourceToken) { IntPtr hInstance = IntPtr.Zero; IntPtr hModule = IntPtr.Zero; try { hInstance = SUIWinAPIs.LoadLibraryEx(resourceToken.ResourceDll, IntPtr.Zero, 2); if(resourceToken.StringID is int) { hModule = SUIWinAPIs.FindResource(hInstance, (int)resourceToken.StringID, (int)resourceToken.StringType); } else { hModule = SUIWinAPIs.FindResource(hInstance, (string)resourceToken.StringID,(int)resourceToken.StringType); } IntPtr hResData = SUIWinAPIs.LoadResource(hInstance, hModule); IntPtr ptr = SUIWinAPIs.LockResource(hResData); DialogTemplateEx dlgtemplateex = new DialogTemplateEx(); DialogTemplate dlgtemplate = new DialogTemplate(); Marshal.PtrToStructure(ptr, dlgtemplateex); Marshal.PtrToStructure(ptr, dlgtemplate); if ((dlgtemplateex.wSignature & 0xffff) == 0xffff) //if dlg is extend dlg { ptr = (IntPtr)(ptr.ToInt64() + Marshal.SizeOf(dlgtemplateex)); //directly operation memory address } else { ptr = (IntPtr)(ptr.ToInt64() + 0x12); } if (Marshal.ReadInt16(ptr) == -1) { ptr = (IntPtr)(ptr.ToInt64() + 4); } else { while (Marshal.ReadInt16(ptr) != 0) { ptr = (IntPtr)(ptr.ToInt64() + 2); } ptr = (IntPtr)(ptr.ToInt64() + 2); } if (Marshal.ReadInt16(ptr) == -1) { ptr = (IntPtr)(ptr.ToInt64() + 4); } else { while (Marshal.ReadInt16(ptr) != 0) { ptr = (IntPtr)(ptr.ToInt64() + 2); } ptr = (IntPtr)(ptr.ToInt64() + 2); } return Marshal.PtrToStringAuto(ptr); } catch (Exception e) { throw new SUIException("ExactString Error",e); } finally { if (!hInstance.Equals(IntPtr.Zero)) SUIWinAPIs.FreeLibrary(hInstance); } }