Как я могу правильно извлечь все контрольные тексты из MFC DLL с C# и P Invoke.
Проблема в том, что есть два формата. Dlgtemplate и dlgtemplateex. Кроме того, в этих ressources есть элементы, и они также имеют два формата. С Findresource, LoadResource, LockResource, EnumResourcenAmes. Тогда я также успешно мог извлечь тексты из диалога. Я перечисляю через диалог ressources, мог бы извлечь идентификатор, заголовок и множество контрольных текстов. И когда я переключаю DLL и использую другой, 50% работает, а другой - нет. Затем я увидел, что расширенные форматы
имеют переменные элементы. Таким образом, у некоторых из них нет статического размера, но каждый диалоговый ресурс может иметь другой. Затем, когда нормальный шаблон выполняется, он итерация проходит через элементы. Но, тем не менее, есть проблемы. И нормальный формат диалога dlgtemplate не работает. Что -то не так.if (isExtended)
{
// ---- DLGTEMPLATEEX ----
ushort dlgVer = (ushort)Marshal.ReadInt16(currentPtr);
currentPtr = IntPtr.Add(currentPtr, 2);
ushort signature = (ushort)Marshal.ReadInt16(currentPtr);
currentPtr = IntPtr.Add(currentPtr, 2);
uint helpID = (uint)Marshal.ReadInt32(currentPtr);
currentPtr = IntPtr.Add(currentPtr, 4);
uint exStyle = (uint)Marshal.ReadInt32(currentPtr);
currentPtr = IntPtr.Add(currentPtr, 4);
uint style = (uint)Marshal.ReadInt32(currentPtr);
currentPtr = IntPtr.Add(currentPtr, 4);
ushort cDlgItems = (ushort)Marshal.ReadInt16(currentPtr);
currentPtr = IntPtr.Add(currentPtr, 2);
short x = (short)Marshal.ReadInt16(currentPtr);
currentPtr = IntPtr.Add(currentPtr, 2);
short y = (short)Marshal.ReadInt16(currentPtr);
currentPtr = IntPtr.Add(currentPtr, 2);
short cx = (short)Marshal.ReadInt16(currentPtr);
currentPtr = IntPtr.Add(currentPtr, 2);
short cy = (short)Marshal.ReadInt16(currentPtr);
currentPtr = IntPtr.Add(currentPtr, 2);
// Variable Fields
SkipDialogField(ref currentPtr); // Menu
SkipDialogField(ref currentPtr); // Window Class
string title = ReadUnicodeString(ref currentPtr); // Dialog Title
result.DialogTitle = title;
if ((style & 0x40) != 0)
{
ushort fontSize = (ushort)Marshal.ReadInt16(currentPtr);
currentPtr = IntPtr.Add(currentPtr, 2);
string fontName = ReadUnicodeString(ref currentPtr);
}
result.ControlTexts = ParseDialogItems(ref currentPtr, cDlgItems, true);
}
else
{
// ---- Standard-DLGTEMPLATE ----
uint style = (uint)Marshal.ReadInt32(currentPtr);
currentPtr = IntPtr.Add(currentPtr, 4);
uint dwExtendedStyle = (uint)Marshal.ReadInt32(currentPtr);
currentPtr = IntPtr.Add(currentPtr, 4);
ushort cdit = (ushort)Marshal.ReadInt16(currentPtr);
currentPtr = IntPtr.Add(currentPtr, 2);
short x = (short)Marshal.ReadInt16(currentPtr);
currentPtr = IntPtr.Add(currentPtr, 2);
short y = (short)Marshal.ReadInt16(currentPtr);
currentPtr = IntPtr.Add(currentPtr, 2);
short cx = (short)Marshal.ReadInt16(currentPtr);
currentPtr = IntPtr.Add(currentPtr, 2);
short cy = (short)Marshal.ReadInt16(currentPtr);
currentPtr = IntPtr.Add(currentPtr, 2);
// Variable Fields: Menu, Window Class, Dialog Title
SkipDialogField(ref currentPtr); // Menu
SkipDialogField(ref currentPtr); // Window Class
string title = ReadUnicodeString(ref currentPtr); // Dialog Title
result.DialogTitle = title;
if ((style & 0x40) != 0)
{
ushort fontSize = (ushort)Marshal.ReadInt16(currentPtr);
currentPtr = IntPtr.Add(currentPtr, 2);
string fontName = ReadUnicodeString(ref currentPtr);
}
result.ControlTexts = ParseDialogItems(ref currentPtr, cdit, false);
}
< /code>
private string ReadUnicodeString(ref IntPtr ptr)
{
StringBuilder sb = new StringBuilder();
long startAddress = ptr.ToInt64();
while (true)
{
char ch = (char)Marshal.ReadInt16(ptr);
ptr = IntPtr.Add(ptr, 2);
if (ch == '\0') break;
sb.Append(ch);
}
return sb.ToString();
}
// To Skip the variable Fields
private void SkipDialogField(ref IntPtr ptr)
{
long startPtr = ptr.ToInt64();
ushort check = (ushort)Marshal.ReadInt16(ptr);
ptr = IntPtr.Add(ptr, 2);
if (check == 0x0000)
{
ptr = IntPtr.Add(ptr, 2);
}
else if (check == 0xFFFF)
{
ptr = IntPtr.Add(ptr, 2);
}
else
{
ReadUnicodeString(ref ptr);
}
}
< /code>
private List ParseDialogItems(ref IntPtr ptr, ushort controlCount, bool isExtended)
{
List controlTexts = new List();
for (int i = 0; i < controlCount; i++)
{
uint style = 0, exStyle = 0;
if (isExtended)
{
ptr = IntPtr.Add(ptr, 4);
exStyle = (uint)Marshal.ReadInt32(ptr);
ptr = IntPtr.Add(ptr, 4);
style = (uint)Marshal.ReadInt32(ptr);
ptr = IntPtr.Add(ptr, 16);
}
else
{
style = (uint)Marshal.ReadInt32(ptr);
ptr = IntPtr.Add(ptr, 4);
exStyle = (uint)Marshal.ReadInt32(ptr);
ptr = IntPtr.Add(ptr, 10);
}
SkipDialogField(ref ptr);
string ctrlText = ReadUnicodeString(ref ptr);
controlTexts.Add(ctrlText);
ushort extraDataSize = (ushort)Marshal.ReadInt16(ptr);
ptr = IntPtr.Add(ptr, 2 + extraDataSize);
}
return controlTexts;
}
< /code>
The Templates can be found in the Microsoft Documentation
I think I have to rework the whole code.
Подробнее здесь: https://stackoverflow.com/questions/795 ... -a-mfc-dll
Как извлечь элементы диалога из MFC DLL ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение