Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3165 lines
102 KiB

  1. //////////////////////////////////////////////
  2. //
  3. // This file has the helper function used in the win32 r/w
  4. // I copied them in this file to share them with the res32 r/w
  5. //
  6. #include <afxwin.h>
  7. #include ".\rwdll.h"
  8. #include ".\rw32hlpr.h"
  9. /////////////////////////////////////////////////////////////////////////////
  10. // Global variables
  11. BYTE sizeofByte = sizeof(BYTE);
  12. BYTE sizeofWord = sizeof(WORD);
  13. BYTE sizeofDWord = sizeof(DWORD);
  14. BYTE sizeofDWordPtr = sizeof(DWORD_PTR);
  15. char szCaption[MAXSTR];
  16. char szUpdCaption[MAXSTR];
  17. WCHAR wszUpdCaption[MAXSTR];
  18. CWordArray wIDArray;
  19. #define DIALOGEX_VERION 1
  20. /////////////////////////////////////////////////////////////////////////////
  21. // Global settings, like code page and append options
  22. UINT g_cp = CP_ACP; // Default to CP_ACP
  23. BOOL g_bAppend = FALSE; // Default to FALSE
  24. BOOL g_bUpdOtherResLang = TRUE; // Default to FALSE
  25. char g_char[] = " "; // Default char for WideChartoMultiByte
  26. VOID InitGlobals()
  27. {
  28. // Make sure we are using the right code page and global settings
  29. // Get the pointer to the function
  30. HINSTANCE hDllInst = LoadLibrary("iodll.dll");
  31. if (hDllInst)
  32. {
  33. UINT (FAR PASCAL * lpfnGetSettings)(LPSETTINGS);
  34. // Get the pointer to the function to get the settings
  35. lpfnGetSettings = (UINT (FAR PASCAL *)(LPSETTINGS))
  36. GetProcAddress( hDllInst, "RSGetGlobals" );
  37. if (lpfnGetSettings!=NULL) {
  38. SETTINGS settings;
  39. (*lpfnGetSettings)(&settings);
  40. g_cp = settings.cp;
  41. g_bAppend = settings.bAppend;
  42. strcpy( g_char, settings.szDefChar );
  43. }
  44. FreeLibrary(hDllInst);
  45. }
  46. }
  47. #define _A_RLT_NULL_ "_RLT32_NULL_"
  48. WCHAR _W_RLT_NULL_[] = L"_RLT32_NULL_";
  49. int _NULL_TAG_LEN_ = wcslen(_W_RLT_NULL_);
  50. ////////////////////////////////////////////////////////////////////////////
  51. // Helper Function Implementation
  52. UINT GetNameOrOrdU( PUCHAR pRes,
  53. ULONG ulId,
  54. LPWSTR lpwszStrId,
  55. DWORD* pdwId )
  56. {
  57. if (ulId & IMAGE_RESOURCE_NAME_IS_STRING) {
  58. PIMAGE_RESOURCE_DIR_STRING_U pStrU = (PIMAGE_RESOURCE_DIR_STRING_U)((BYTE *)pRes
  59. + (ulId & (~IMAGE_RESOURCE_NAME_IS_STRING)));
  60. for (USHORT usCount=0; usCount < pStrU->Length ; usCount++) {
  61. *(lpwszStrId++) = LOBYTE(pStrU->NameString[usCount]);
  62. }
  63. *(lpwszStrId++) = 0x0000;
  64. *pdwId = 0;
  65. } else {
  66. *lpwszStrId = 0x0000;
  67. *pdwId = ulId;
  68. }
  69. return ERROR_NO_ERROR;
  70. }
  71. UINT _MBSTOWCS( WCHAR * pwszOut, CHAR * pszIn, UINT nLength)
  72. {
  73. //
  74. // Check if we have a pointer to the function
  75. //
  76. int rc = MultiByteToWideChar(
  77. g_cp, // UINT CodePage,
  78. 0, // DWORD dwFlags,
  79. pszIn, // LPCSTR lpMultiByteStr,
  80. -1, // int cchMultiByte,
  81. pwszOut, // unsigned int far * lpWideCharStr, // LPWSTR
  82. nLength ); // int cchWideChar
  83. return rc;
  84. }
  85. UINT _WCSTOMBS( CHAR* pszOut, WCHAR* pwszIn, UINT nLength)
  86. {
  87. BOOL Bool = FALSE;
  88. int rc = WideCharToMultiByte(
  89. g_cp, // UINT CodePage,
  90. 0, // DWORD dwFlags,
  91. pwszIn, // const unsigned int far * lpWideCharStr, // LPCWSTR
  92. -1, // int cchWideChar,
  93. pszOut, // LPSTR lpMultiByteStr,
  94. nLength, // int cchMultiByte,
  95. g_char, // LPCSTR lpDefaultChar,
  96. &Bool); // BOOL far * lpUsedDefaultChar); // LPBOOL
  97. return rc;
  98. }
  99. UINT _WCSLEN( WCHAR * pwszIn )
  100. {
  101. UINT n = 0;
  102. while( *(pwszIn+n)!=0x0000 ) n++;
  103. return( n + 1 );
  104. }
  105. BYTE
  106. PutByte( BYTE far * far* lplpBuf, BYTE bValue, LONG* pdwSize )
  107. {
  108. if (*pdwSize>=sizeofByte){
  109. memcpy(*lplpBuf, &bValue, sizeofByte);
  110. *lplpBuf += sizeofByte;
  111. *pdwSize -= sizeofByte;
  112. } else *pdwSize = -1;
  113. return sizeofByte;
  114. }
  115. UINT
  116. PutNameOrOrd( BYTE far * far* lplpBuf, WORD wOrd, LPSTR lpszText, LONG* pdwSize )
  117. {
  118. UINT uiSize = 0;
  119. if (wOrd) {
  120. uiSize += PutWord(lplpBuf, 0xFFFF, pdwSize);
  121. uiSize += PutWord(lplpBuf, wOrd, pdwSize);
  122. } else {
  123. uiSize += PutStringW(lplpBuf, lpszText, pdwSize);
  124. }
  125. return uiSize;
  126. }
  127. UINT
  128. PutCaptionOrOrd( BYTE far * far* lplpBuf, WORD wOrd, LPSTR lpszText, LONG* pdwSize,
  129. WORD wClass, DWORD dwStyle )
  130. {
  131. UINT uiSize = 0;
  132. // If this is an ICON then can just be an ID
  133. // Fix bug in the RC compiler
  134. /*
  135. if( (wClass==0x0082) && ((dwStyle & 0xF)==SS_ICON) ) {
  136. if (wOrd) {
  137. uiSize += PutWord(lplpBuf, 0xFFFF, pdwSize);
  138. uiSize += PutWord(lplpBuf, wOrd, pdwSize);
  139. return uiSize;
  140. } else {
  141. // put nothing
  142. return 0;
  143. }
  144. }
  145. */
  146. if (wOrd) {
  147. uiSize += PutWord(lplpBuf, 0xFFFF, pdwSize);
  148. uiSize += PutWord(lplpBuf, wOrd, pdwSize);
  149. } else {
  150. uiSize += PutStringW(lplpBuf, lpszText, pdwSize);
  151. }
  152. return uiSize;
  153. }
  154. UINT
  155. PutStringA( BYTE far * far* lplpBuf, LPSTR lpszText, LONG* pdwSize )
  156. {
  157. int iSize = strlen(lpszText)+1;
  158. if (*pdwSize>=iSize){
  159. memcpy(*lplpBuf, lpszText, iSize);
  160. *lplpBuf += iSize;
  161. *pdwSize -= iSize;
  162. } else *pdwSize = -1;
  163. return iSize;
  164. }
  165. UINT
  166. PutStringW( BYTE far * far* lplpBuf, LPSTR lpszText, LONG* pdwSize )
  167. {
  168. int iSize = strlen(lpszText)+1;
  169. if (*pdwSize>=(iSize*2)){
  170. WCHAR* lpwszStr = new WCHAR[(iSize*2)];
  171. if (!lpwszStr) *pdwSize =0;
  172. else {
  173. SetLastError(0);
  174. iSize = _MBSTOWCS( lpwszStr, lpszText, iSize*2 );
  175. // Check for error
  176. if(GetLastError())
  177. return ERROR_DLL_LOAD;
  178. memcpy(*lplpBuf, lpwszStr, (iSize*2));
  179. *lplpBuf += (iSize*2);
  180. *pdwSize -= (iSize*2);
  181. delete lpwszStr;
  182. }
  183. } else *pdwSize = -1;
  184. return (iSize*2);
  185. }
  186. BYTE
  187. PutWord( BYTE far * far* lplpBuf, WORD wValue, LONG* pdwSize )
  188. {
  189. if (*pdwSize>=sizeofWord){
  190. memcpy(*lplpBuf, &wValue, sizeofWord);
  191. *lplpBuf += sizeofWord;
  192. *pdwSize -= sizeofWord;
  193. } else *pdwSize = -1;
  194. return sizeofWord;
  195. }
  196. BYTE
  197. PutDWord( BYTE far * far* lplpBuf, DWORD dwValue, LONG* pdwSize )
  198. {
  199. if (*pdwSize>=sizeofDWord){
  200. memcpy(*lplpBuf, &dwValue, sizeofDWord);
  201. *lplpBuf += sizeofDWord;
  202. *pdwSize -= sizeofDWord;
  203. } else *pdwSize = -1;
  204. return sizeofDWord;
  205. }
  206. BYTE
  207. PutDWordPtr( BYTE far * far* lplpBuf, DWORD_PTR dwValue, LONG* pdwSize )
  208. {
  209. if (*pdwSize>=sizeofDWordPtr){
  210. memcpy(*lplpBuf, &dwValue, sizeofDWordPtr);
  211. *lplpBuf += sizeofDWordPtr;
  212. *pdwSize -= sizeofDWordPtr;
  213. } else *pdwSize = -1;
  214. return sizeofDWordPtr;
  215. }
  216. DWORD CalcID( WORD wId, BOOL bFlag )
  217. {
  218. // We want to calculate the ID Relative to the WORD wId
  219. // If we have any other ID with the same value then we return
  220. // the incremental number + the value.
  221. // If no other Item have been found then the incremental number will be 0.
  222. // If bFlag = TRUE then the id get added to the present list.
  223. // If bFlag = FALSE then the list is reseted and the function return
  224. // Clean the array if needed
  225. if(!bFlag) {
  226. wIDArray.RemoveAll();
  227. wIDArray.SetSize(30, 1);
  228. return 0;
  229. }
  230. // Add the value to the array
  231. wIDArray.Add(wId);
  232. // Walk the array to get the number of duplicated ID
  233. int c = -1; // will be 0 based
  234. for(INT_PTR i=wIDArray.GetUpperBound(); i>=0 ; i-- ) {
  235. if (wIDArray.GetAt(i)==wId)
  236. c++;
  237. }
  238. TRACE3("CalcID: ID: %d\tPos: %d\tFinal: %u\n", wId, c, MAKELONG( wId, c ));
  239. return MAKELONG( wId, c );
  240. }
  241. UINT
  242. ParseAccel( LPVOID lpImageBuf, DWORD dwISize, LPVOID lpBuffer, DWORD dwSize )
  243. {
  244. BYTE far * lpImage = (BYTE far *)lpImageBuf;
  245. LONG dwImageSize = dwISize;
  246. BYTE far * lpBuf = (BYTE far *)lpBuffer;
  247. LONG dwBufSize = dwSize;
  248. BYTE far * lpItem = (BYTE far *)lpBuffer;
  249. UINT uiOffset = 0;
  250. LONG lDummy;
  251. LONG dwOverAllSize = 0L;
  252. typedef struct accelerator {
  253. WORD fFlags;
  254. WORD wAscii;
  255. WORD wId;
  256. WORD padding;
  257. } ACCEL, *PACCEL;
  258. PACCEL pAcc = (PACCEL)lpImage;
  259. // Reset the IDArray
  260. CalcID(0, FALSE);
  261. // get the number of entry in the table
  262. for( int cNumEntry =(int)(dwImageSize/sizeof(ACCEL)), c=1; c<=cNumEntry ; c++)
  263. {
  264. // Fixed field
  265. dwOverAllSize += PutDWord( &lpBuf, 0, &dwBufSize);
  266. // We don't have the size and pos in a menu
  267. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  268. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  269. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  270. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  271. // we don't have checksum and style
  272. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  273. dwOverAllSize += PutDWord( &lpBuf, (DWORD)pAcc->wAscii, &dwBufSize);
  274. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  275. //Put the Flag
  276. dwOverAllSize += PutDWord( &lpBuf, (DWORD)pAcc->fFlags, &dwBufSize);
  277. //Put the MenuId
  278. dwOverAllSize += PutDWord( &lpBuf, CalcID(pAcc->wId, TRUE), &dwBufSize);
  279. // we don't have the resID, and the Type Id
  280. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  281. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  282. // we don't have the language
  283. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  284. // we don't have the codepage or the font name
  285. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  286. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  287. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  288. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  289. dwOverAllSize += PutByte( &lpBuf, (BYTE)-1, &dwBufSize);
  290. dwOverAllSize += PutByte( &lpBuf, (BYTE)-1, &dwBufSize);
  291. // Let's put null were we don;t have the strings
  292. uiOffset = sizeof(RESITEM);
  293. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize);
  294. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize);
  295. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize);
  296. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize);
  297. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize);
  298. // Put the size of the resource
  299. if (dwBufSize>=0) {
  300. lDummy = 8;
  301. PutDWord( &lpItem, (DWORD)uiOffset, &lDummy);
  302. }
  303. // Move to the next position
  304. if (dwBufSize>0)
  305. lpItem = lpBuf;
  306. pAcc++;
  307. }
  308. return (UINT)(dwOverAllSize);
  309. }
  310. UINT GenerateAccel( LPVOID lpNewBuf, LONG dwNewSize,
  311. LPVOID lpNewI, DWORD* pdwNewImageSize )
  312. {
  313. UINT uiError = ERROR_NO_ERROR;
  314. BYTE * lpNewImage = (BYTE *) lpNewI;
  315. LONG dwNewImageSize = *pdwNewImageSize;
  316. BYTE * lpBuf = (BYTE *) lpNewBuf;
  317. LPRESITEM lpResItem = LPNULL;
  318. typedef struct accelerator {
  319. WORD fFlags;
  320. WORD wAscii;
  321. WORD wId;
  322. WORD padding;
  323. } ACCEL, *PACCEL;
  324. ACCEL acc;
  325. BYTE bAccSize = sizeof(ACCEL);
  326. LONG dwOverAllSize = 0l;
  327. while(dwNewSize>0) {
  328. if (dwNewSize ) {
  329. lpResItem = (LPRESITEM) lpBuf;
  330. acc.wId = LOWORD(lpResItem->dwItemID);
  331. acc.fFlags = (WORD)lpResItem->dwFlags;
  332. acc.wAscii = (WORD)lpResItem->dwStyle;
  333. acc.padding = 0;
  334. lpBuf += lpResItem->dwSize;
  335. dwNewSize -= lpResItem->dwSize;
  336. }
  337. if (dwNewSize<=0) {
  338. // Last Item in the accel table, mark it
  339. acc.fFlags = acc.fFlags | 0x80;
  340. }
  341. TRACE3("Accel: wID: %hd\t wAscii: %hd\t wFlag: %hd\n", acc.wId, acc.wAscii, acc.fFlags);
  342. if(bAccSize<=dwNewImageSize)
  343. {
  344. memcpy(lpNewImage, &acc, bAccSize);
  345. dwNewImageSize -= bAccSize;
  346. lpNewImage = lpNewImage+bAccSize;
  347. dwOverAllSize += bAccSize;
  348. }
  349. else dwOverAllSize += bAccSize;
  350. }
  351. if (dwOverAllSize>(LONG)*pdwNewImageSize) {
  352. // calc the padding as well
  353. dwOverAllSize += (BYTE)Pad16((DWORD)(dwOverAllSize));
  354. *pdwNewImageSize = dwOverAllSize;
  355. return uiError;
  356. }
  357. *pdwNewImageSize = *pdwNewImageSize-dwNewImageSize;
  358. if(*pdwNewImageSize>0) {
  359. // calculate padding
  360. BYTE bPad = (BYTE)Pad16((DWORD)(*pdwNewImageSize));
  361. if (bPad>dwNewImageSize) {
  362. *pdwNewImageSize += bPad;
  363. return uiError;
  364. }
  365. memset(lpNewImage, 0x00, bPad);
  366. *pdwNewImageSize += bPad;
  367. }
  368. return uiError;
  369. }
  370. UINT
  371. UpdateAccel( LPVOID lpNewBuf, LONG dwNewSize,
  372. LPVOID lpOldI, LONG dwOldImageSize,
  373. LPVOID lpNewI, DWORD* pdwNewImageSize )
  374. {
  375. UINT uiError = ERROR_NO_ERROR;
  376. TRACE("Update Accelerators:\n");
  377. BYTE far * lpNewImage = (BYTE far *) lpNewI;
  378. LONG dwNewImageSize = *pdwNewImageSize;
  379. BYTE far * lpOldImage = (BYTE far *) lpOldI;
  380. DWORD dwOriginalOldSize = dwOldImageSize;
  381. BYTE far * lpBuf = (BYTE far *) lpNewBuf;
  382. LPRESITEM lpResItem = LPNULL;
  383. WORD wDummy;
  384. //Old Items
  385. WORD fFlags = 0;
  386. WORD wEvent = 0;
  387. WORD wId = 0;
  388. WORD wPos = 0;
  389. // Updated items
  390. WORD fUpdFlags = 0;
  391. WORD wUpdEvent = 0;
  392. WORD wUpdId = 0;
  393. WORD wUpdPos = 0;
  394. LONG dwOverAllSize = 0l;
  395. while(dwOldImageSize>0) {
  396. wPos++;
  397. // Get the information from the old image
  398. GetWord( &lpOldImage, &fFlags, &dwOldImageSize );
  399. GetWord( &lpOldImage, &wEvent, &dwOldImageSize );
  400. GetWord( &lpOldImage, &wId, &dwOldImageSize );
  401. GetWord( &lpOldImage, &wDummy, &dwOldImageSize );
  402. TRACE3("Old: fFlags: %d\t wEvent: %d\t wId: %d\n",fFlags, wEvent, wId);
  403. if ((!wUpdPos) && dwNewSize ) {
  404. lpResItem = (LPRESITEM) lpBuf;
  405. wUpdId = LOWORD(lpResItem->dwItemID);
  406. wUpdPos = HIWORD(lpResItem->dwItemID);
  407. fUpdFlags = (WORD)lpResItem->dwFlags;
  408. wUpdEvent = (WORD)lpResItem->dwStyle;
  409. lpBuf += lpResItem->dwSize;
  410. dwNewSize -= lpResItem->dwSize;
  411. }
  412. if ((wUpdId==wId)) {
  413. fFlags = fUpdFlags;
  414. wEvent = wUpdEvent;
  415. wUpdPos = 0;
  416. }
  417. TRACE3("New: fFlags: %d\t wEvent: %d\t wId: %d\n",fFlags, wEvent, wId);
  418. dwOverAllSize += PutWord( &lpNewImage, fFlags, &dwNewImageSize);
  419. dwOverAllSize += PutWord( &lpNewImage, wEvent, &dwNewImageSize);
  420. dwOverAllSize += PutWord( &lpNewImage, wId, &dwNewImageSize);
  421. dwOverAllSize += PutWord( &lpNewImage, 0, &dwNewImageSize);
  422. }
  423. if (dwOverAllSize>(LONG)*pdwNewImageSize) {
  424. // calc the padding as well
  425. BYTE bPad = (BYTE)Pad4((DWORD)(dwOverAllSize));
  426. dwOverAllSize += bPad;
  427. *pdwNewImageSize = dwOverAllSize;
  428. return uiError;
  429. }
  430. *pdwNewImageSize = *pdwNewImageSize-dwNewImageSize;
  431. if(*pdwNewImageSize>0) {
  432. // calculate padding
  433. BYTE bPad = (BYTE)Pad4((DWORD)(*pdwNewImageSize));
  434. if (bPad>dwNewImageSize) {
  435. *pdwNewImageSize += bPad;
  436. return uiError;
  437. }
  438. memset(lpNewImage, 0x00, bPad);
  439. *pdwNewImageSize += bPad;
  440. }
  441. return uiError;
  442. }
  443. UINT
  444. ParseMenu( LPVOID lpImageBuf, DWORD dwISize, LPVOID lpBuffer, DWORD dwSize )
  445. {
  446. BYTE far * lpImage = (BYTE far *)lpImageBuf;
  447. LONG dwImageSize = dwISize;
  448. BYTE far * lpBuf = (BYTE far *)lpBuffer;
  449. LONG dwBufSize = dwSize;
  450. BYTE far * lpItem = (BYTE far *)lpBuffer;
  451. UINT uiOffset = 0;
  452. LONG lDummy;
  453. LONG dwOverAllSize = 0L;
  454. BOOL bExt = FALSE;
  455. WORD wlen = 0;
  456. // Menu Template
  457. WORD wMenuVer = 0;
  458. WORD wHdrSize = 0;
  459. // get the menu header
  460. GetWord( &lpImage, &wMenuVer, &dwImageSize );
  461. GetWord( &lpImage, &wHdrSize, &dwImageSize );
  462. // Check if is one of the new extended resource
  463. if(wMenuVer == 1) {
  464. bExt = TRUE;
  465. SkipByte( &lpImage, wHdrSize, &dwImageSize );
  466. }
  467. // Menu Items
  468. WORD fItemFlags = 0;
  469. WORD wMenuId = 0;
  470. // Extended Menu Items
  471. DWORD dwType = 0L;
  472. DWORD dwState = 0L;
  473. DWORD dwID = 0L;
  474. DWORD dwHelpID = 0;
  475. while(dwImageSize>0) {
  476. // Fixed field
  477. dwOverAllSize += PutDWord( &lpBuf, 0, &dwBufSize);
  478. // We don't have the size and pos in a menu
  479. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  480. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  481. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  482. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  483. // we don't have checksum and style
  484. dwOverAllSize += PutDWord( &lpBuf, (WORD)-1, &dwBufSize);
  485. dwOverAllSize += PutDWord( &lpBuf, (WORD)-1, &dwBufSize);
  486. dwOverAllSize += PutDWord( &lpBuf, (WORD)-1, &dwBufSize);
  487. if(bExt) {
  488. GetDWord( &lpImage, &dwType, &dwImageSize );
  489. GetDWord( &lpImage, &dwState, &dwImageSize );
  490. GetDWord( &lpImage, &dwID, &dwImageSize );
  491. // Let's get the Menu flags
  492. GetWord( &lpImage, &fItemFlags, &dwImageSize );
  493. // Check if it is a MFR_POPUP 0x0001
  494. if (fItemFlags & MFR_POPUP) {
  495. // convert to the standard value
  496. fItemFlags &= ~(WORD)MFR_POPUP;
  497. fItemFlags |= MF_POPUP;
  498. }
  499. //Put the Flag
  500. dwOverAllSize += PutDWord( &lpBuf, (DWORD)fItemFlags, &dwBufSize);
  501. //Put the MenuId
  502. dwOverAllSize += PutDWord( &lpBuf, dwID, &dwBufSize);
  503. } else {
  504. // Let's get the Menu flags
  505. GetWord( &lpImage, &fItemFlags, &dwImageSize );
  506. if ( !(fItemFlags & MF_POPUP) )
  507. // Get the menu Id
  508. GetWord( &lpImage, &wMenuId, &dwImageSize );
  509. else wMenuId = (WORD)-1;
  510. //Put the Flag
  511. dwOverAllSize += PutDWord( &lpBuf, (DWORD)fItemFlags, &dwBufSize);
  512. //Put the MenuId
  513. dwOverAllSize += PutDWord( &lpBuf, (DWORD)wMenuId, &dwBufSize);
  514. }
  515. // we don't have the resID, and the Type Id
  516. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  517. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  518. // we don't have the language
  519. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  520. // we don't have the codepage or the font name
  521. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  522. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  523. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  524. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  525. dwOverAllSize += PutByte( &lpBuf, (BYTE)-1, &dwBufSize);
  526. dwOverAllSize += PutByte( &lpBuf, (BYTE)-1, &dwBufSize);
  527. // Let's put null were we don;t have the strings
  528. uiOffset = sizeof(RESITEM);
  529. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize);
  530. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize);
  531. dwOverAllSize += PutDWordPtr( &lpBuf, (DWORD_PTR)(lpItem+uiOffset), &dwBufSize);
  532. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize);
  533. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize);
  534. // Get the text
  535. // calculate were the string is going to be
  536. // Will be the fixed header+the pointer
  537. wlen = (WORD)GetStringW( &lpImage, &szCaption[0], &dwImageSize, MAXSTR );
  538. dwOverAllSize += PutStringA( &lpBuf, &szCaption[0], &dwBufSize);
  539. if(bExt) {
  540. // Do we need padding
  541. BYTE bPad = (BYTE)Pad4((WORD)(wlen+sizeofWord));
  542. SkipByte( &lpImage, bPad, &dwImageSize );
  543. if ( (fItemFlags & MF_POPUP) )
  544. // Get the Help Id
  545. GetDWord( &lpImage, &dwHelpID, &dwImageSize );
  546. }
  547. // Put the size of the resource
  548. uiOffset += strlen(szCaption)+1;
  549. // Check if we are alligned
  550. lDummy = Allign( &lpBuf, &dwBufSize, (LONG)uiOffset);
  551. dwOverAllSize += lDummy;
  552. uiOffset += lDummy;
  553. lDummy = 4;
  554. if(dwBufSize>=0)
  555. PutDWord( &lpItem, (DWORD)uiOffset, &lDummy);
  556. /*
  557. if (dwBufSize>=0) {
  558. uiOffset += strlen((LPSTR)(lpItem+uiOffset))+1;
  559. // Check if we are alligned
  560. lDummy = Allign( &lpBuf, &dwBufSize, (LONG)uiOffset);
  561. dwOverAllSize += lDummy;
  562. uiOffset += lDummy;
  563. lDummy = 8;
  564. PutDWord( &lpItem, (DWORD)uiOffset, &lDummy);
  565. }
  566. */
  567. // Move to the next position
  568. lpItem = lpBuf;
  569. if (dwImageSize<=16) {
  570. // Check if we are at the end and this is just padding
  571. BYTE bPad = (BYTE)Pad16((DWORD)(dwISize-dwImageSize));
  572. if (bPad==dwImageSize) {
  573. BYTE far * lpBuf = lpImage;
  574. while (bPad){
  575. if(*lpBuf++!=0x00)
  576. break;
  577. bPad--;
  578. }
  579. if (bPad==0)
  580. dwImageSize = -1;
  581. }
  582. }
  583. }
  584. return (UINT)(dwOverAllSize);
  585. }
  586. UINT
  587. UpdateMenu( LPVOID lpNewBuf, LONG dwNewSize,
  588. LPVOID lpOldI, LONG dwOldImageSize,
  589. LPVOID lpNewI, DWORD* pdwNewImageSize )
  590. {
  591. UINT uiError = ERROR_NO_ERROR;
  592. BYTE far * lpNewImage = (BYTE far *) lpNewI;
  593. LONG dwNewImageSize = *pdwNewImageSize;
  594. BYTE far * lpOldImage = (BYTE far *) lpOldI;
  595. DWORD dwOriginalOldSize = dwOldImageSize;
  596. BYTE far * lpBuf = (BYTE far *) lpNewBuf;
  597. LPRESITEM lpResItem = LPNULL;
  598. // We have to read the information from the lpNewBuf
  599. // Menu Items
  600. WORD fItemFlags;
  601. WORD wMenuId;
  602. WORD wPos = 0;
  603. // Updated items
  604. WORD wUpdPos = 0;
  605. WORD fUpdItemFlags;
  606. WORD wUpdMenuId;
  607. // Extended Menu Items
  608. DWORD dwType = 0L;
  609. DWORD dwState = 0L;
  610. DWORD dwID = 0L;
  611. DWORD dwHelpID = 0;
  612. LONG dwOverAllSize = 0l;
  613. WORD wlen = 0;
  614. BOOL bExt = FALSE;
  615. BYTE bPad = 0;
  616. // Menu Template
  617. WORD wMenuVer = 0;
  618. WORD wHdrSize = 0;
  619. // get the menu header
  620. GetWord( &lpOldImage, &wMenuVer, &dwOldImageSize );
  621. GetWord( &lpOldImage, &wHdrSize, &dwOldImageSize );
  622. // Check if is one of the new extended resource
  623. if(wMenuVer == 1) {
  624. bExt = TRUE;
  625. // Put the header informations
  626. dwOverAllSize += PutWord( &lpNewImage, wMenuVer, &dwNewImageSize);
  627. dwOverAllSize += PutWord( &lpNewImage, wHdrSize, &dwNewImageSize);
  628. if(wHdrSize) {
  629. while(wHdrSize) {
  630. dwOldImageSize -= PutByte( &lpNewImage, *((BYTE*)lpOldImage), &dwNewImageSize);
  631. lpOldImage += sizeofByte;
  632. dwOverAllSize += sizeofByte;
  633. wHdrSize--;
  634. }
  635. }
  636. }
  637. else {
  638. // Put the header informations
  639. dwOverAllSize += PutWord( &lpNewImage, wMenuVer, &dwNewImageSize);
  640. dwOverAllSize += PutWord( &lpNewImage, wHdrSize, &dwNewImageSize);
  641. }
  642. while(dwOldImageSize>0) {
  643. wPos++;
  644. // Get the information from the old image
  645. // Get the menu flag
  646. if(bExt) {
  647. GetDWord( &lpOldImage, &dwType, &dwOldImageSize );
  648. GetDWord( &lpOldImage, &dwState, &dwOldImageSize );
  649. GetDWord( &lpOldImage, &dwID, &dwOldImageSize );
  650. wMenuId = LOWORD(dwID); // we need to do this since we had no idea the ID could be DWORD
  651. // Let's get the Menu flags
  652. GetWord( &lpOldImage, &fItemFlags, &dwOldImageSize );
  653. // Get the text
  654. wlen = (WORD)GetStringW( &lpOldImage, &szCaption[0], &dwOldImageSize, MAXSTR );
  655. // Do we need padding
  656. bPad = (BYTE)Pad4((WORD)(wlen+sizeofWord));
  657. SkipByte( &lpOldImage, bPad, &dwOldImageSize );
  658. if ( (fItemFlags & MFR_POPUP) )
  659. // Get the Help Id
  660. GetDWord( &lpOldImage, &dwHelpID, &dwOldImageSize );
  661. } else {
  662. // Let's get the Menu flags
  663. GetWord( &lpOldImage, &fItemFlags, &dwOldImageSize );
  664. if ( !(fItemFlags & MF_POPUP) )
  665. // Get the menu Id
  666. GetWord( &lpOldImage, &wMenuId, &dwOldImageSize );
  667. else wMenuId = (WORD)-1;
  668. // Get the text
  669. GetStringW( &lpOldImage, &szCaption[0], &dwOldImageSize, MAXSTR );
  670. }
  671. if ((!wUpdPos) && dwNewSize ) {
  672. lpResItem = (LPRESITEM) lpBuf;
  673. wUpdPos = HIWORD(lpResItem->dwItemID);
  674. wUpdMenuId = LOWORD(lpResItem->dwItemID);
  675. fUpdItemFlags = (WORD)lpResItem->dwFlags;
  676. strcpy( szUpdCaption, lpResItem->lpszCaption );
  677. lpBuf += lpResItem->dwSize;
  678. dwNewSize -= lpResItem->dwSize;
  679. }
  680. if ((wPos==wUpdPos) && (wUpdMenuId==wMenuId)) {
  681. if ((fItemFlags & MFR_POPUP) && bExt) {
  682. fUpdItemFlags &= ~MF_POPUP;
  683. fUpdItemFlags |= MFR_POPUP;
  684. }
  685. // check if it is not the last item in the menu
  686. if(fItemFlags & MF_END)
  687. fItemFlags = fUpdItemFlags | (WORD)MF_END;
  688. else fItemFlags = fUpdItemFlags;
  689. // check it is not a separator
  690. if((fItemFlags==0) && (wMenuId==0) && !(*szCaption))
  691. strcpy(szCaption, "");
  692. else strcpy(szCaption, szUpdCaption);
  693. wUpdPos = 0;
  694. }
  695. if(bExt) {
  696. dwOverAllSize += PutDWord( &lpNewImage, dwType, &dwNewImageSize);
  697. dwOverAllSize += PutDWord( &lpNewImage, dwState, &dwNewImageSize);
  698. dwOverAllSize += PutDWord( &lpNewImage, dwID, &dwNewImageSize);
  699. dwOverAllSize += PutWord( &lpNewImage, fItemFlags, &dwNewImageSize);
  700. wlen = (WORD)PutStringW( &lpNewImage, &szCaption[0], &dwNewImageSize);
  701. dwOverAllSize += wlen;
  702. // Do we need padding
  703. bPad = (BYTE)Pad4((WORD)(wlen+sizeofWord));
  704. while(bPad) {
  705. dwOverAllSize += PutByte( &lpNewImage, 0, &dwNewImageSize);
  706. bPad--;
  707. }
  708. if ( (fItemFlags & MFR_POPUP) )
  709. // write the Help Id
  710. dwOverAllSize += PutDWord( &lpNewImage, dwHelpID, &dwNewImageSize);
  711. }
  712. else {
  713. dwOverAllSize += PutWord( &lpNewImage, fItemFlags, &dwNewImageSize);
  714. if ( !(fItemFlags & MF_POPUP) ) {
  715. dwOverAllSize += PutWord( &lpNewImage, wMenuId, &dwNewImageSize);
  716. }
  717. // Write the text in UNICODE
  718. dwOverAllSize += PutStringW( &lpNewImage, &szCaption[0], &dwNewImageSize);
  719. }
  720. if (dwOldImageSize<=16) {
  721. // Check if we are at the end and this is just padding
  722. BYTE bPad = (BYTE)Pad16((DWORD)(dwOriginalOldSize-dwOldImageSize));
  723. if (bPad==dwOldImageSize) {
  724. BYTE far * lpBuf = lpOldImage;
  725. while (bPad){
  726. if(*lpBuf++!=0x00)
  727. break;
  728. bPad--;
  729. }
  730. if (bPad==0)
  731. dwOldImageSize = -1;
  732. }
  733. }
  734. }
  735. if (dwOverAllSize>(LONG)*pdwNewImageSize) {
  736. // calc the padding as well
  737. BYTE bPad = (BYTE)Pad16((DWORD)(dwOverAllSize));
  738. dwOverAllSize += bPad;
  739. *pdwNewImageSize = dwOverAllSize;
  740. return uiError;
  741. }
  742. *pdwNewImageSize = *pdwNewImageSize-dwNewImageSize;
  743. if(*pdwNewImageSize>0) {
  744. // calculate padding
  745. BYTE bPad = (BYTE)Pad16((DWORD)(*pdwNewImageSize));
  746. if (bPad>dwNewImageSize) {
  747. *pdwNewImageSize += bPad;
  748. return uiError;
  749. }
  750. memset(lpNewImage, 0x00, bPad);
  751. *pdwNewImageSize += bPad;
  752. }
  753. return uiError;
  754. }
  755. UINT
  756. ParseString( LPVOID lpImageBuf, DWORD dwISize, LPVOID lpBuffer, DWORD dwSize )
  757. {
  758. // Should be almost impossible for a String to be Huge
  759. BYTE far * lpImage = (BYTE far *)lpImageBuf;
  760. LONG dwImageSize = dwISize;
  761. BYTE far * lpBuf = (BYTE far *)lpBuffer;
  762. LONG dwBufSize = dwSize;
  763. BYTE far * lpItem = (BYTE far *)lpBuffer;
  764. UINT uiOffset = 0;
  765. LONG lDummy;
  766. LONG dwOverAllSize = 0L;
  767. LONG dwRead = 0L;
  768. BYTE bIdCount = 0;
  769. while( (dwImageSize>0) && (bIdCount<16) ) {
  770. // Fixed field
  771. dwOverAllSize += PutDWord( &lpBuf, 0, &dwBufSize);
  772. // We don't have the size and pos in a string
  773. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  774. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  775. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  776. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  777. // we don't have checksum and style
  778. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  779. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  780. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  781. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  782. //Put the StringId
  783. dwOverAllSize += PutDWord( &lpBuf, bIdCount++, &dwBufSize);
  784. // we don't have the resID, and the Type Id
  785. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  786. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  787. // we don't have the language
  788. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  789. // we don't have the codepage or the font name
  790. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  791. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  792. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  793. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  794. dwOverAllSize += PutByte( &lpBuf, (BYTE)-1, &dwBufSize);
  795. dwOverAllSize += PutByte( &lpBuf, (BYTE)-1, &dwBufSize);
  796. // Let's put null were we don;t have the strings
  797. uiOffset = sizeof(RESITEM);
  798. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize); // ClassName
  799. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize); // FaceName
  800. dwOverAllSize += PutDWordPtr( &lpBuf, (DWORD_PTR)(lpItem+uiOffset), &dwBufSize); // Caption
  801. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize); // ResItem
  802. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize); // TypeItem
  803. // Get the text
  804. GetPascalString( &lpImage, &szCaption[0], MAXSTR, &dwImageSize );
  805. dwOverAllSize += PutStringA( &lpBuf, &szCaption[0], &dwBufSize);
  806. // Put the size of the resource
  807. uiOffset += strlen(szCaption)+1;
  808. // Check if we are alligned
  809. lDummy = Allign( &lpBuf, &dwBufSize, (LONG)uiOffset);
  810. dwOverAllSize += lDummy;
  811. uiOffset += lDummy;
  812. lDummy = 4;
  813. if(dwBufSize>=0)
  814. PutDWord( &lpItem, (DWORD)uiOffset, &lDummy);
  815. /*
  816. if ((LONG)(dwSize-dwOverAllSize)>=0) {
  817. uiOffset += strlen(szCaption)+1;
  818. // Check if we are alligned
  819. lDummy = Allign( &lpBuf, &dwBufSize, (LONG)uiOffset);
  820. dwOverAllSize += lDummy;
  821. uiOffset += lDummy;
  822. lDummy = 8;
  823. PutDWord( &lpItem, (DWORD)uiOffset, &lDummy);
  824. }
  825. */
  826. // Move to the next position
  827. lpItem = lpBuf;
  828. // Check if we are at the end and this is just padding
  829. if (dwImageSize<=16 && (bIdCount==16)) {
  830. // Check if we are at the end and this is just padding
  831. BYTE bPad = (BYTE)Pad16((DWORD)(dwISize-dwImageSize));
  832. if (bPad==dwImageSize) {
  833. BYTE far * lpBuf = lpImage;
  834. while (bPad){
  835. if(*lpBuf++!=0x00)
  836. break;
  837. bPad--;
  838. }
  839. if (bPad==0)
  840. dwImageSize = -1;
  841. }
  842. }
  843. }
  844. return (UINT)(dwOverAllSize);
  845. }
  846. UINT
  847. UpdateString( LPVOID lpNewBuf, LONG dwNewSize,
  848. LPVOID lpOldI, LONG dwOldImageSize,
  849. LPVOID lpNewI, DWORD* pdwNewImageSize )
  850. {
  851. UINT uiError = ERROR_NO_ERROR;
  852. LONG dwNewImageSize = *pdwNewImageSize;
  853. BYTE far * lpNewImage = (BYTE far *) lpNewI;
  854. BYTE far * lpOldImage = (BYTE far *) lpOldI;
  855. BYTE far * lpBuf = (BYTE far *) lpNewBuf;
  856. LPRESITEM lpResItem = LPNULL;
  857. // We have to read the information from the lpNewBuf
  858. WORD wLen;
  859. WORD wPos = 0;
  860. // Updated info
  861. WORD wUpdPos = 0;
  862. DWORD dwOriginalOldSize = dwOldImageSize;
  863. LONG dwOverAllSize = 0l;
  864. while(dwOldImageSize>0) {
  865. wPos++;
  866. // Get the information from the old image
  867. GetPascalString( &lpOldImage, &szCaption[0], MAXSTR, &dwOldImageSize );
  868. if ((!wUpdPos) && dwNewSize ) {
  869. lpResItem = (LPRESITEM) lpBuf;
  870. wUpdPos = HIWORD(lpResItem->dwItemID);
  871. strcpy( szUpdCaption, lpResItem->lpszCaption );
  872. lpBuf += lpResItem->dwSize;
  873. dwNewSize -= lpResItem->dwSize;
  874. }
  875. if ((wPos==wUpdPos)) {
  876. strcpy(szCaption, szUpdCaption);
  877. wUpdPos = 0;
  878. }
  879. wLen = strlen(szCaption);
  880. // Write the text
  881. dwOverAllSize += PutPascalStringW( &lpNewImage, &szCaption[0], wLen, &dwNewImageSize );
  882. }
  883. if (dwOverAllSize>(LONG)*pdwNewImageSize) {
  884. // calc the padding as well
  885. BYTE bPad = (BYTE)Pad4((DWORD)(dwOverAllSize));
  886. dwOverAllSize += bPad;
  887. *pdwNewImageSize = dwOverAllSize;
  888. return uiError;
  889. }
  890. *pdwNewImageSize = *pdwNewImageSize-dwNewImageSize;
  891. if(*pdwNewImageSize>0) {
  892. // calculate padding
  893. BYTE bPad = (BYTE)Pad4((DWORD)(*pdwNewImageSize));
  894. if (bPad>dwNewImageSize) {
  895. *pdwNewImageSize += bPad;
  896. return uiError;
  897. }
  898. memset(lpNewImage, 0x00, bPad);
  899. *pdwNewImageSize += bPad;
  900. }
  901. return uiError;
  902. }
  903. UINT
  904. UpdateMsgTbl( LPVOID lpNewBuf, LONG dwNewSize,
  905. LPVOID lpOldI, LONG dwOldImageSize,
  906. LPVOID lpNewI, DWORD* pdwNewImageSize )
  907. {
  908. UINT uiError = ERROR_NO_ERROR;
  909. LONG dwNewImageSize = *pdwNewImageSize;
  910. BYTE far * lpNewImage = (BYTE far *) lpNewI;
  911. BYTE far * lpStartImage = (BYTE far *) lpNewI;
  912. BYTE far * lpOldImage = (BYTE far *) lpOldI;
  913. BYTE far * lpBuf = (BYTE far *) lpNewBuf;
  914. LPRESITEM lpResItem = LPNULL;
  915. // We have to read the information from the lpNewBuf
  916. WORD wPos = 0;
  917. // Updated info
  918. WORD wUpdPos = 0;
  919. WORD wUpdId = 0;
  920. DWORD dwOriginalOldSize = dwOldImageSize;
  921. LONG dwOverAllSize = 0l;
  922. ULONG ulNumofBlock = 0;
  923. ULONG ulLowId = 0l;
  924. ULONG ulHighId = 0l;
  925. ULONG ulOffsetToEntry = 0l;
  926. USHORT usLength = 0l;
  927. USHORT usFlags = 0l;
  928. // we have to calculate the position of the first Entry block in the immage
  929. // Get number of blocks in the old image
  930. GetDWord( &lpOldImage, &ulNumofBlock, &dwOldImageSize );
  931. BYTE far * lpEntryBlock = lpNewImage+(ulNumofBlock*sizeof(ULONG)*3+sizeof(ULONG));
  932. // Write the number of block in the new image
  933. dwOverAllSize = PutDWord( &lpNewImage, ulNumofBlock, &dwNewImageSize );
  934. wPos = 1;
  935. for( ULONG c = 0; c<ulNumofBlock ; c++) {
  936. // Get ID of the block
  937. GetDWord( &lpOldImage, &ulLowId, &dwOldImageSize );
  938. GetDWord( &lpOldImage, &ulHighId, &dwOldImageSize );
  939. // Write the Id of the block
  940. dwOverAllSize += PutDWord( &lpNewImage, ulLowId, &dwNewImageSize );
  941. dwOverAllSize += PutDWord( &lpNewImage, ulHighId, &dwNewImageSize );
  942. // Get the offset to the data in the old image
  943. GetDWord( &lpOldImage, &ulOffsetToEntry, &dwOldImageSize );
  944. // Write the offset to the data in the new Image
  945. dwOverAllSize += PutDWord( &lpNewImage, (DWORD)(lpEntryBlock-lpStartImage), &dwNewImageSize );
  946. BYTE far * lpData = (BYTE far *)lpOldI;
  947. lpData += ulOffsetToEntry;
  948. while( ulHighId>=ulLowId ) {
  949. GetMsgStr( &lpData,
  950. &szCaption[0],
  951. MAXSTR,
  952. &usLength,
  953. &usFlags,
  954. &dwOldImageSize );
  955. if ( dwNewSize ) {
  956. lpResItem = (LPRESITEM) lpBuf;
  957. wUpdId = LOWORD(lpResItem->dwItemID);
  958. strcpy( szUpdCaption, lpResItem->lpszCaption );
  959. lpBuf += lpResItem->dwSize;
  960. dwNewSize -= lpResItem->dwSize;
  961. }
  962. // Check if the item has been updated
  963. if (wUpdId==wPos++) {
  964. strcpy(szCaption, szUpdCaption);
  965. }
  966. dwOverAllSize += PutMsgStr( &lpEntryBlock,
  967. &szCaption[0],
  968. usFlags,
  969. &dwNewImageSize );
  970. ulLowId++;
  971. }
  972. }
  973. if (dwOverAllSize>(LONG)*pdwNewImageSize) {
  974. // calc the padding as well
  975. BYTE bPad = (BYTE)Pad4((DWORD)(dwOverAllSize));
  976. dwOverAllSize += bPad;
  977. *pdwNewImageSize = dwOverAllSize;
  978. return uiError;
  979. }
  980. *pdwNewImageSize = *pdwNewImageSize-dwNewImageSize;
  981. if(*pdwNewImageSize>0) {
  982. // calculate padding
  983. BYTE bPad = (BYTE)Pad4((DWORD)(*pdwNewImageSize));
  984. if (bPad>dwNewImageSize) {
  985. *pdwNewImageSize += bPad;
  986. return uiError;
  987. }
  988. memset(lpNewImage, 0x00, bPad);
  989. *pdwNewImageSize += bPad;
  990. }
  991. return uiError;
  992. }
  993. UINT
  994. ParseDialog( LPVOID lpImageBuf, DWORD dwISize, LPVOID lpBuffer, DWORD dwSize )
  995. {
  996. BYTE far * lpImage = (BYTE far *)lpImageBuf;
  997. LONG dwImageSize = dwISize;
  998. BYTE far * lpBuf = (BYTE far *)lpBuffer;
  999. LONG dwBufSize = dwSize;
  1000. LPRESITEM lpResItem = (LPRESITEM)lpBuffer;
  1001. UINT uiOffset = 0;
  1002. char far * lpStrBuf = (char far *)(lpBuf+sizeof(RESITEM));
  1003. LONG dwOverAllSize = 0L;
  1004. WORD wIdCount = 0;
  1005. BOOL bExt = FALSE; // Extended dialog flag
  1006. // Dialog Elements
  1007. WORD wDlgVer = 0;
  1008. WORD wSign = 0;
  1009. DWORD dwHelpID = 0L;
  1010. DWORD dwStyle = 0L;
  1011. DWORD dwExtStyle = 0L;
  1012. WORD wNumOfElem = 0;
  1013. WORD wX = 0;
  1014. WORD wY = 0;
  1015. WORD wcX = 0;
  1016. WORD wcY = 0;
  1017. WORD wId = 0;
  1018. DWORD dwId = 0L;
  1019. char szMenuName[128];
  1020. WORD wMenuName;
  1021. char szClassName[128];
  1022. WORD wClassName;
  1023. WORD wOrd = 0;
  1024. WORD wPointSize = 0;
  1025. WORD wWeight = -1;
  1026. BYTE bItalic = -1;
  1027. BYTE bCharSet = DEFAULT_CHARSET;
  1028. char szFaceName[128];
  1029. WORD wRawData = 0;
  1030. WORD wDataSize = 0;
  1031. szCaption[0] = '\0';
  1032. // read the dialog header
  1033. wDataSize = GetDWord( &lpImage, &dwStyle, &dwImageSize );
  1034. // Check for extended dialog style
  1035. if(HIWORD(dwStyle)==0xFFFF) {
  1036. bExt = TRUE;
  1037. wDlgVer = HIWORD(dwStyle);
  1038. wSign = LOWORD(dwStyle);
  1039. wDataSize += GetDWord( &lpImage, &dwHelpID, &dwImageSize );
  1040. }
  1041. wDataSize += GetDWord( &lpImage, &dwExtStyle, &dwImageSize );
  1042. if(bExt)
  1043. wDataSize += GetDWord( &lpImage, &dwStyle, &dwImageSize );
  1044. wDataSize += GetWord( &lpImage, &wNumOfElem, &dwImageSize );
  1045. wDataSize += GetWord( &lpImage, &wX, &dwImageSize );
  1046. wDataSize += GetWord( &lpImage, &wY, &dwImageSize );
  1047. wDataSize += GetWord( &lpImage, &wcX, &dwImageSize );
  1048. wDataSize += GetWord( &lpImage, &wcY, &dwImageSize );
  1049. wDataSize += (WORD)GetNameOrOrd( &lpImage, &wMenuName, &szMenuName[0], &dwImageSize );
  1050. wDataSize += (WORD)GetClassName( &lpImage, &wClassName, &szClassName[0], &dwImageSize );
  1051. wDataSize += (WORD)GetCaptionOrOrd( &lpImage, &wOrd, &szCaption[0], &dwImageSize, wClassName, dwStyle );
  1052. if( dwStyle & DS_SETFONT ) {
  1053. wDataSize += GetWord( &lpImage, &wPointSize, &dwImageSize );
  1054. if(bExt) {
  1055. wDataSize += GetWord( &lpImage, &wWeight, &dwImageSize );
  1056. wDataSize += GetByte( &lpImage, &bItalic, &dwImageSize );
  1057. wDataSize += GetByte( &lpImage, &bCharSet, &dwImageSize );
  1058. }
  1059. wDataSize += (WORD)GetStringW( &lpImage, &szFaceName[0], &dwImageSize, 128 );
  1060. }
  1061. // calculate the padding
  1062. BYTE bPad = (BYTE)Pad4((WORD)wDataSize);
  1063. if (bPad)
  1064. SkipByte( &lpImage, bPad, &dwImageSize );
  1065. TRACE("WIN32.DLL ParseDialog\t");
  1066. if(bExt)
  1067. TRACE("Extended style Dialog - Chicago win32 dialog format\n");
  1068. else TRACE("Standart style Dialog - NT win32 dialog format\n");
  1069. if (bExt){
  1070. TRACE1("DlgVer: %d\t", wDlgVer);
  1071. TRACE1("Signature: %d\t", wSign);
  1072. TRACE1("HelpID: %lu\n", dwHelpID);
  1073. }
  1074. TRACE1("NumElem: %d\t", wNumOfElem);
  1075. TRACE1("X %d\t", wX);
  1076. TRACE1("Y: %d\t", wY);
  1077. TRACE1("CX: %d\t", wcX);
  1078. TRACE1("CY: %d\t", wcY);
  1079. TRACE1("Id: %d\t", wId);
  1080. TRACE1("Style: %lu\t", dwStyle);
  1081. TRACE1("ExtStyle: %lu\n", dwExtStyle);
  1082. TRACE1("Caption: %s\n", szCaption);
  1083. TRACE2("ClassName: %s\tClassId: %d\n", szClassName, wClassName );
  1084. TRACE2("MenuName: %s\tMenuId: %d\n", szMenuName, wMenuName );
  1085. TRACE2("FontName: %s\tPoint: %d\n", szFaceName, wPointSize );
  1086. #ifdef _DEBUG
  1087. if(bExt)
  1088. TRACE2("Weight: %d\tItalic: %d\n", wWeight, bItalic );
  1089. #endif
  1090. // Fixed field
  1091. dwOverAllSize += PutDWord( &lpBuf, 0, &dwBufSize);
  1092. dwOverAllSize += PutWord( &lpBuf, wX, &dwBufSize);
  1093. dwOverAllSize += PutWord( &lpBuf, wY, &dwBufSize);
  1094. dwOverAllSize += PutWord( &lpBuf, wcX, &dwBufSize);
  1095. dwOverAllSize += PutWord( &lpBuf, wcY, &dwBufSize);
  1096. // we don't have checksum
  1097. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1098. dwOverAllSize += PutDWord( &lpBuf, dwStyle, &dwBufSize);
  1099. dwOverAllSize += PutDWord( &lpBuf, dwExtStyle, &dwBufSize);
  1100. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1101. //Put the Id 0 for the main dialog
  1102. dwOverAllSize += PutDWord( &lpBuf, wIdCount++, &dwBufSize);
  1103. // we don't have the resID, and the Type Id
  1104. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1105. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1106. // we don't have the language
  1107. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1108. // we don't have the codepage
  1109. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1110. dwOverAllSize += PutWord( &lpBuf, wClassName, &dwBufSize);
  1111. dwOverAllSize += PutWord( &lpBuf, wPointSize, &dwBufSize);
  1112. dwOverAllSize += PutWord( &lpBuf, wWeight, &dwBufSize);
  1113. dwOverAllSize += PutByte( &lpBuf, bItalic, &dwBufSize);
  1114. dwOverAllSize += PutByte( &lpBuf, bCharSet, &dwBufSize);
  1115. // Let's put null were we don't have the strings
  1116. uiOffset = sizeof(RESITEM);
  1117. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize); // ClassName
  1118. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize); // FaceName
  1119. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize); // Caption
  1120. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize); // ResItem
  1121. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize); // TypeItem
  1122. lpResItem->lpszClassName = strcpy( lpStrBuf, szClassName );
  1123. lpStrBuf += strlen(lpResItem->lpszClassName)+1;
  1124. lpResItem->lpszFaceName = strcpy( lpStrBuf, szFaceName );
  1125. lpStrBuf += strlen(lpResItem->lpszFaceName)+1;
  1126. lpResItem->lpszCaption = strcpy( lpStrBuf, szCaption );
  1127. lpStrBuf += strlen(lpResItem->lpszCaption)+1;
  1128. // Put the size of the resource
  1129. if (dwBufSize>0) {
  1130. uiOffset += strlen((LPSTR)(lpResItem->lpszClassName))+1;
  1131. uiOffset += strlen((LPSTR)(lpResItem->lpszFaceName))+1;
  1132. uiOffset += strlen((LPSTR)(lpResItem->lpszCaption))+1;
  1133. }
  1134. // Check if we are alligned
  1135. uiOffset += Allign( (LPLPBYTE)&lpStrBuf, &dwBufSize, (LONG)uiOffset);
  1136. dwOverAllSize += uiOffset-sizeof(RESITEM);
  1137. lpResItem->dwSize = (DWORD)uiOffset;
  1138. // Move to the next position
  1139. lpResItem = (LPRESITEM) lpStrBuf;
  1140. lpBuf = (BYTE far *)lpStrBuf;
  1141. lpStrBuf = (char far *)(lpBuf+sizeof(RESITEM));
  1142. while( (dwImageSize>0) && (wNumOfElem>0) ) {
  1143. // Read the Controls
  1144. if(bExt) {
  1145. wDataSize = GetDWord( &lpImage, &dwHelpID, &dwImageSize );
  1146. wDataSize += GetDWord( &lpImage, &dwExtStyle, &dwImageSize );
  1147. wDataSize += GetDWord( &lpImage, &dwStyle, &dwImageSize );
  1148. }
  1149. else {
  1150. wDataSize = GetDWord( &lpImage, &dwStyle, &dwImageSize );
  1151. wDataSize += GetDWord( &lpImage, &dwExtStyle, &dwImageSize );
  1152. }
  1153. wDataSize += GetWord( &lpImage, &wX, &dwImageSize );
  1154. wDataSize += GetWord( &lpImage, &wY, &dwImageSize );
  1155. wDataSize += GetWord( &lpImage, &wcX, &dwImageSize );
  1156. wDataSize += GetWord( &lpImage, &wcY, &dwImageSize );
  1157. if(bExt) {
  1158. wDataSize += GetDWord( &lpImage, &dwId, &dwImageSize );
  1159. wId = LOWORD(dwId);
  1160. }
  1161. else wDataSize += GetWord( &lpImage, &wId, &dwImageSize );
  1162. wDataSize += (WORD)GetClassName( &lpImage, &wClassName, &szClassName[0], &dwImageSize );
  1163. wDataSize += (WORD)GetCaptionOrOrd( &lpImage, &wOrd, &szCaption[0], &dwImageSize, wClassName, dwStyle );
  1164. if (bExt) {
  1165. wDataSize += GetWord( &lpImage, &wRawData, &dwImageSize );
  1166. wDataSize += (WORD)SkipByte( &lpImage, wRawData, &dwImageSize );
  1167. } else
  1168. wDataSize += (WORD)SkipByte( &lpImage, 2, &dwImageSize );
  1169. // Calculate padding
  1170. bPad = (BYTE)Pad4((WORD)wDataSize);
  1171. if (bPad)
  1172. SkipByte( &lpImage, bPad, &dwImageSize );
  1173. wNumOfElem--;
  1174. // Fixed field
  1175. dwOverAllSize += PutDWord( &lpBuf, 0, &dwBufSize);
  1176. dwOverAllSize += PutWord( &lpBuf, wX, &dwBufSize);
  1177. dwOverAllSize += PutWord( &lpBuf, wY, &dwBufSize);
  1178. dwOverAllSize += PutWord( &lpBuf, wcX, &dwBufSize);
  1179. dwOverAllSize += PutWord( &lpBuf, wcY, &dwBufSize);
  1180. // we don't have checksum and extended style
  1181. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1182. dwOverAllSize += PutDWord( &lpBuf, dwStyle, &dwBufSize);
  1183. dwOverAllSize += PutDWord( &lpBuf, dwExtStyle, &dwBufSize);
  1184. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1185. //Put the Id
  1186. dwOverAllSize += PutDWord( &lpBuf, wId, &dwBufSize);
  1187. // we don't have the resID, and the Type Id
  1188. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1189. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1190. // we don't have the language
  1191. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1192. // we don't have the codepage
  1193. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1194. dwOverAllSize += PutWord( &lpBuf, wClassName, &dwBufSize);
  1195. dwOverAllSize += PutWord( &lpBuf, wPointSize, &dwBufSize);
  1196. dwOverAllSize += PutWord( &lpBuf, wWeight, &dwBufSize);
  1197. dwOverAllSize += PutByte( &lpBuf, bItalic, &dwBufSize);
  1198. dwOverAllSize += PutByte( &lpBuf, bCharSet, &dwBufSize);
  1199. // Let's put null were we don't have the strings
  1200. uiOffset = sizeof(RESITEM);
  1201. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize); // ClassName
  1202. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize); // FaceName
  1203. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize); // Caption
  1204. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize); // ResItem
  1205. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize); // TypeItem
  1206. lpResItem->lpszClassName = strcpy( lpStrBuf, szClassName );
  1207. lpStrBuf += strlen(lpResItem->lpszClassName)+1;
  1208. lpResItem->lpszFaceName = strcpy( lpStrBuf, szFaceName );
  1209. lpStrBuf += strlen(lpResItem->lpszFaceName)+1;
  1210. lpResItem->lpszCaption = strcpy( lpStrBuf, szCaption );
  1211. lpStrBuf += strlen(lpResItem->lpszCaption)+1;
  1212. // Put the size of the resource
  1213. if (dwBufSize>0) {
  1214. uiOffset += strlen((LPSTR)(lpResItem->lpszClassName))+1;
  1215. uiOffset += strlen((LPSTR)(lpResItem->lpszFaceName))+1;
  1216. uiOffset += strlen((LPSTR)(lpResItem->lpszCaption))+1;
  1217. }
  1218. // Check if we are alligned
  1219. uiOffset += Allign( (LPLPBYTE)&lpStrBuf, &dwBufSize, (LONG)uiOffset);
  1220. dwOverAllSize += uiOffset-sizeof(RESITEM);
  1221. lpResItem->dwSize = (DWORD)uiOffset;
  1222. // Move to the next position
  1223. lpResItem = (LPRESITEM) lpStrBuf;
  1224. lpBuf = (BYTE far *)lpStrBuf;
  1225. lpStrBuf = (char far *)(lpBuf+sizeof(RESITEM));
  1226. TRACE1("\tControl: X: %d\t", wX);
  1227. TRACE1("Y: %d\t", wY);
  1228. TRACE1("CX: %d\t", wcX);
  1229. TRACE1("CY: %d\t", wcY);
  1230. if (bExt) TRACE1("Id: %lu\t", dwId);
  1231. else TRACE1("Id: %d\t", wId);
  1232. TRACE1("Style: %lu\t", dwStyle);
  1233. TRACE1("ExtStyle: %lu\n", dwExtStyle);
  1234. TRACE1("HelpID: %lu\t", dwHelpID);
  1235. TRACE1("RawData: %d\n", wRawData);
  1236. TRACE1("Caption: %s\n", szCaption);
  1237. if (dwImageSize<=16) {
  1238. // Check if we are at the end and this is just padding
  1239. BYTE bPad = (BYTE)Pad16((DWORD)(dwISize-dwImageSize));
  1240. if (bPad==dwImageSize) {
  1241. BYTE far * lpBuf = lpImage;
  1242. while (bPad){
  1243. if(*lpBuf++!=0x00)
  1244. break;
  1245. bPad--;
  1246. }
  1247. if (bPad==0)
  1248. dwImageSize = -1;
  1249. }
  1250. }
  1251. }
  1252. return (UINT)(dwOverAllSize);
  1253. }
  1254. UINT
  1255. UpdateDialog( LPVOID lpNewBuf, LONG dwNewSize,
  1256. LPVOID lpOldI, LONG dwOldImageSize,
  1257. LPVOID lpNewI, DWORD* pdwNewImageSize )
  1258. {
  1259. UINT uiError = ERROR_NO_ERROR;
  1260. BYTE far * lpNewImage = (BYTE far *) lpNewI;
  1261. LONG dwNewImageSize = *pdwNewImageSize;
  1262. BYTE far * lpOldImage = (BYTE far *) lpOldI;
  1263. LONG dwOriginalOldSize = dwOldImageSize;
  1264. BYTE far * lpBuf = (BYTE far *) lpNewBuf;
  1265. LPRESITEM lpResItem = LPNULL;
  1266. LONG dwOverAllSize = 0L;
  1267. //WORD wIdCount = 0;
  1268. BOOL bExt = FALSE; // Extended dialog flag
  1269. BOOL bUpdExt = FALSE; // Updated DIALOGEX flag
  1270. // Updated elements
  1271. WORD wUpdX = 0;
  1272. WORD wUpdY = 0;
  1273. WORD wUpdcX = 0;
  1274. WORD wUpdcY = 0;
  1275. DWORD dwUpdStyle = 0l;
  1276. DWORD dwUpdExtStyle = 0L;
  1277. DWORD dwPosId = 0l;
  1278. char szUpdFaceName[128];
  1279. WORD wUpdPointSize = 0;
  1280. BYTE bUpdCharSet = DEFAULT_CHARSET;
  1281. WORD wUpdPos = 0;
  1282. // Dialog Elements
  1283. WORD wDlgVer = 0;
  1284. WORD wSign = 0;
  1285. DWORD dwHelpID = 0L;
  1286. DWORD dwID = 0L;
  1287. DWORD dwStyle = 0L;
  1288. DWORD dwExtStyle = 0L;
  1289. WORD wNumOfElem = 0;
  1290. WORD wX = 0;
  1291. WORD wY = 0;
  1292. WORD wcX = 0;
  1293. WORD wcY = 0;
  1294. WORD wId = 0;
  1295. char szMenuName[128];
  1296. WORD wMenuName;
  1297. char szClassName[128];
  1298. WORD wClassName;
  1299. WORD wPointSize = 0;
  1300. WORD wWeight = FW_NORMAL;
  1301. BYTE bItalic = 0;
  1302. BYTE bCharSet = DEFAULT_CHARSET;
  1303. char szFaceName[128];
  1304. WORD wRawData = 0;
  1305. BYTE * lpRawData = NULL;
  1306. WORD wDataSize = 0;
  1307. WORD wPos = 1;
  1308. WORD wOrd = 0;
  1309. // read the dialog header
  1310. wDataSize = GetDWord( &lpOldImage, &dwStyle, &dwOriginalOldSize );
  1311. // Check for extended dialog style
  1312. if(HIWORD(dwStyle)==0xFFFF) {
  1313. bExt = TRUE;
  1314. wDlgVer = HIWORD(dwStyle);
  1315. wSign = LOWORD(dwStyle);
  1316. wDataSize += GetDWord( &lpOldImage, &dwHelpID, &dwOriginalOldSize );
  1317. }
  1318. wDataSize += GetDWord( &lpOldImage, &dwExtStyle, &dwOriginalOldSize );
  1319. if(bExt)
  1320. wDataSize += GetDWord( &lpOldImage, &dwStyle, &dwOriginalOldSize );
  1321. wDataSize += GetWord( &lpOldImage, &wNumOfElem, &dwOriginalOldSize );
  1322. wDataSize += GetWord( &lpOldImage, &wX, &dwOriginalOldSize );
  1323. wDataSize += GetWord( &lpOldImage, &wY, &dwOriginalOldSize );
  1324. wDataSize += GetWord( &lpOldImage, &wcX, &dwOriginalOldSize );
  1325. wDataSize += GetWord( &lpOldImage, &wcY, &dwOriginalOldSize );
  1326. wDataSize += (WORD)GetNameOrOrd( &lpOldImage, &wMenuName, &szMenuName[0], &dwOriginalOldSize );
  1327. wDataSize += (WORD)GetClassName( &lpOldImage, &wClassName, &szClassName[0], &dwOriginalOldSize );
  1328. wDataSize += (WORD)GetCaptionOrOrd( &lpOldImage , &wOrd, &szCaption[0], &dwOriginalOldSize, wClassName, dwStyle );
  1329. if( dwStyle & DS_SETFONT ) {
  1330. wDataSize += GetWord( &lpOldImage, &wPointSize, &dwOriginalOldSize );
  1331. if(bExt) {
  1332. wDataSize += GetWord( &lpOldImage, &wWeight, &dwOriginalOldSize );
  1333. wDataSize += GetByte( &lpOldImage, &bItalic, &dwOriginalOldSize );
  1334. wDataSize += GetByte( &lpOldImage, &bCharSet, &dwOriginalOldSize );
  1335. }
  1336. wDataSize += (WORD)GetStringW( &lpOldImage, &szFaceName[0], &dwOriginalOldSize, 128 );
  1337. }
  1338. // calculate the padding
  1339. BYTE bPad = (BYTE)Pad4((WORD)wDataSize);
  1340. if (bPad)
  1341. SkipByte( &lpOldImage, bPad, &dwOriginalOldSize );
  1342. TRACE("WIN32.DLL UpdateDialog\n");
  1343. if(bExt)
  1344. TRACE("Extended style Dialog - Chicago win32 dialog format\n");
  1345. else TRACE("Standart style Dialog - NT win32 dialog format\n");
  1346. if (bExt){
  1347. TRACE1("DlgVer: %d\t", wDlgVer);
  1348. TRACE1("Signature: %d\t", wSign);
  1349. TRACE1("HelpID: %lu\n", dwHelpID);
  1350. }
  1351. TRACE1("NumElem: %d\t", wNumOfElem);
  1352. TRACE1("X %d\t", wX);
  1353. TRACE1("Y: %d\t", wY);
  1354. TRACE1("CX: %d\t", wcX);
  1355. TRACE1("CY: %d\t", wcY);
  1356. TRACE1("Id: %d\t", wId);
  1357. TRACE1("Style: %lu\t", dwStyle);
  1358. TRACE1("ExtStyle: %lu\n", dwExtStyle);
  1359. TRACE1("Caption: %s\n", szCaption);
  1360. TRACE2("ClassName: %s\tClassId: %d\n", szClassName, wClassName );
  1361. TRACE2("MenuName: %s\tMenuId: %d\n", szMenuName, wMenuName );
  1362. TRACE2("FontName: %s\tPoint: %d\n", szFaceName, wPointSize );
  1363. #ifdef _DEBUG
  1364. if(bExt)
  1365. TRACE2("Weight: %d\tItalic: %d\n", wWeight, bItalic );
  1366. #endif
  1367. // Get the infrmation from the updated resource
  1368. if ((!wUpdPos) && dwNewSize ) {
  1369. lpResItem = (LPRESITEM) lpBuf;
  1370. wUpdX = lpResItem->wX;
  1371. wUpdY = lpResItem->wY;
  1372. wUpdcX = lpResItem->wcX;
  1373. wUpdcY = lpResItem->wcY;
  1374. wUpdPointSize = lpResItem->wPointSize;
  1375. bUpdCharSet = lpResItem->bCharSet;
  1376. dwUpdStyle = lpResItem->dwStyle;
  1377. dwUpdExtStyle = lpResItem->dwExtStyle;
  1378. dwPosId = lpResItem->dwItemID;
  1379. strcpy( szUpdCaption, lpResItem->lpszCaption );
  1380. strcpy( szUpdFaceName, lpResItem->lpszFaceName );
  1381. lpBuf += lpResItem->dwSize;
  1382. dwNewSize -= lpResItem->dwSize;
  1383. }
  1384. // check if we have to update the header
  1385. if ((HIWORD(dwPosId)==wPos) && (LOWORD(dwPosId)==wId)) {
  1386. wX = wUpdX;
  1387. wY = wUpdY;
  1388. wcX = wUpdcX;
  1389. wcY = wUpdcY;
  1390. wPointSize = wUpdPointSize;
  1391. bCharSet = bUpdCharSet;
  1392. dwStyle = dwUpdStyle;
  1393. dwExtStyle = dwUpdExtStyle;
  1394. strcpy(szCaption, szUpdCaption);
  1395. strcpy(szFaceName, szUpdFaceName);
  1396. }
  1397. // User changed DIALOG to DIALOGEX by adding charset information.
  1398. if (!bExt && bCharSet != DEFAULT_CHARSET){
  1399. bUpdExt = TRUE;
  1400. wSign = DIALOGEX_VERION;
  1401. wDlgVer = 0xFFFF;
  1402. dwHelpID = 0;
  1403. wWeight = FW_NORMAL;
  1404. bItalic = 0;
  1405. }
  1406. DWORD dwPadCalc = dwOverAllSize;
  1407. // Write the header informations
  1408. if(bExt || bUpdExt) {
  1409. dwOverAllSize += PutWord( &lpNewImage, wSign, &dwNewImageSize );
  1410. dwOverAllSize += PutWord( &lpNewImage, wDlgVer, &dwNewImageSize );
  1411. dwOverAllSize += PutDWord( &lpNewImage, dwHelpID, &dwNewImageSize );
  1412. dwOverAllSize += PutDWord( &lpNewImage, dwExtStyle, &dwNewImageSize );
  1413. dwOverAllSize += PutDWord( &lpNewImage, dwStyle, &dwNewImageSize );
  1414. }
  1415. else {
  1416. dwOverAllSize += PutDWord( &lpNewImage, dwStyle, &dwNewImageSize );
  1417. dwOverAllSize += PutDWord( &lpNewImage, dwExtStyle, &dwNewImageSize );
  1418. }
  1419. dwOverAllSize += PutWord( &lpNewImage, wNumOfElem, &dwNewImageSize );
  1420. dwOverAllSize += PutWord( &lpNewImage, wX, &dwNewImageSize );
  1421. dwOverAllSize += PutWord( &lpNewImage, wY, &dwNewImageSize );
  1422. dwOverAllSize += PutWord( &lpNewImage, wcX, &dwNewImageSize );
  1423. dwOverAllSize += PutWord( &lpNewImage, wcY, &dwNewImageSize );
  1424. dwOverAllSize += PutNameOrOrd( &lpNewImage, wMenuName, &szMenuName[0], &dwNewImageSize );
  1425. dwOverAllSize += PutClassName( &lpNewImage, wClassName, &szClassName[0], &dwNewImageSize );
  1426. dwOverAllSize += PutCaptionOrOrd( &lpNewImage, wOrd, &szCaption[0], &dwNewImageSize,
  1427. wClassName, dwStyle );
  1428. if( dwStyle & DS_SETFONT ) {
  1429. dwOverAllSize += PutWord( &lpNewImage, wPointSize, &dwNewImageSize );
  1430. if(bExt || bUpdExt) {
  1431. dwOverAllSize += PutWord( &lpNewImage, wWeight, &dwNewImageSize );
  1432. dwOverAllSize += PutByte( &lpNewImage, bItalic, &dwNewImageSize );
  1433. dwOverAllSize += PutByte( &lpNewImage, bCharSet, &dwNewImageSize );
  1434. }
  1435. dwOverAllSize += PutStringW( &lpNewImage, &szFaceName[0], &dwNewImageSize );
  1436. }
  1437. // Check if padding is needed
  1438. bPad = (BYTE)Pad4((WORD)(dwOverAllSize-dwPadCalc));
  1439. if (bPad) {
  1440. if( (bPad)<=dwNewImageSize )
  1441. memset( lpNewImage, 0x00, bPad );
  1442. dwNewImageSize -= (bPad);
  1443. dwOverAllSize += (bPad);
  1444. lpNewImage += (bPad);
  1445. }
  1446. while( (dwOriginalOldSize>0) && (wNumOfElem>0) ) {
  1447. wPos++;
  1448. // Get the info for the control
  1449. // Read the Controls
  1450. if(bExt) {
  1451. wDataSize = GetDWord( &lpOldImage, &dwHelpID, &dwOriginalOldSize );
  1452. wDataSize += GetDWord( &lpOldImage, &dwExtStyle, &dwOriginalOldSize );
  1453. wDataSize += GetDWord( &lpOldImage, &dwStyle, &dwOriginalOldSize );
  1454. }
  1455. else {
  1456. wDataSize = GetDWord( &lpOldImage, &dwStyle, &dwOriginalOldSize );
  1457. wDataSize += GetDWord( &lpOldImage, &dwExtStyle, &dwOriginalOldSize );
  1458. }
  1459. wDataSize += GetWord( &lpOldImage, &wX, &dwOriginalOldSize );
  1460. wDataSize += GetWord( &lpOldImage, &wY, &dwOriginalOldSize );
  1461. wDataSize += GetWord( &lpOldImage, &wcX, &dwOriginalOldSize );
  1462. wDataSize += GetWord( &lpOldImage, &wcY, &dwOriginalOldSize );
  1463. if(bExt) {
  1464. wDataSize += GetDWord( &lpOldImage, &dwID, &dwOriginalOldSize );
  1465. wId = LOWORD(dwID);
  1466. } else {
  1467. wDataSize += GetWord( &lpOldImage, &wId, &dwOriginalOldSize );
  1468. }
  1469. wDataSize += (WORD)GetClassName( &lpOldImage, &wClassName, &szClassName[0], &dwOriginalOldSize );
  1470. wDataSize += (WORD)GetCaptionOrOrd( &lpOldImage, &wOrd, &szCaption[0], &dwOriginalOldSize, wClassName, dwStyle );
  1471. if (bExt) {
  1472. wDataSize += GetWord( &lpOldImage, &wRawData, &dwOriginalOldSize );
  1473. if(wRawData) {
  1474. lpRawData = (BYTE*)lpOldImage;
  1475. wDataSize += (WORD)SkipByte( &lpOldImage, wRawData, &dwOriginalOldSize );
  1476. } else lpRawData = NULL;
  1477. } else
  1478. wDataSize += (WORD)SkipByte( &lpOldImage, 2, &dwOriginalOldSize );
  1479. // Calculate padding
  1480. bPad = (BYTE)Pad4((WORD)wDataSize);
  1481. if (bPad)
  1482. SkipByte( &lpOldImage, bPad, &dwOriginalOldSize );
  1483. wNumOfElem--;
  1484. if ((!wUpdPos) && dwNewSize ) {
  1485. TRACE1("\t\tUpdateDialog:\tdwNewSize=%ld\n",(LONG)dwNewSize);
  1486. TRACE1("\t\t\t\tlpszCaption=%Fs\n",lpResItem->lpszCaption);
  1487. lpResItem = (LPRESITEM) lpBuf;
  1488. wUpdX = lpResItem->wX;
  1489. wUpdY = lpResItem->wY;
  1490. wUpdcX = lpResItem->wcX;
  1491. wUpdcY = lpResItem->wcY;
  1492. dwUpdStyle = lpResItem->dwStyle;
  1493. dwUpdExtStyle = lpResItem->dwExtStyle;
  1494. dwPosId = lpResItem->dwItemID;
  1495. strcpy( szUpdCaption, lpResItem->lpszCaption );
  1496. lpBuf += lpResItem->dwSize;
  1497. dwNewSize -= lpResItem->dwSize;
  1498. }
  1499. // check if we have to update the header
  1500. if ((HIWORD(dwPosId)==wPos) && (LOWORD(dwPosId)==wId)) {
  1501. wX = wUpdX;
  1502. wY = wUpdY;
  1503. wcX = wUpdcX;
  1504. wcY = wUpdcY;
  1505. dwStyle = dwUpdStyle;
  1506. dwExtStyle = dwUpdExtStyle;
  1507. strcpy(szCaption, szUpdCaption);
  1508. }
  1509. dwPadCalc = dwOverAllSize;
  1510. //write the control
  1511. if(bExt || bUpdExt) {
  1512. dwOverAllSize += PutDWord( &lpNewImage, dwHelpID, &dwNewImageSize );
  1513. dwOverAllSize += PutDWord( &lpNewImage, dwExtStyle, &dwNewImageSize );
  1514. dwOverAllSize += PutDWord( &lpNewImage, dwStyle, &dwNewImageSize );
  1515. }
  1516. else {
  1517. dwOverAllSize += PutDWord( &lpNewImage, dwStyle, &dwNewImageSize );
  1518. dwOverAllSize += PutDWord( &lpNewImage, dwExtStyle, &dwNewImageSize );
  1519. }
  1520. dwOverAllSize += PutWord( &lpNewImage, wX, &dwNewImageSize );
  1521. dwOverAllSize += PutWord( &lpNewImage, wY, &dwNewImageSize );
  1522. dwOverAllSize += PutWord( &lpNewImage, wcX, &dwNewImageSize );
  1523. dwOverAllSize += PutWord( &lpNewImage, wcY, &dwNewImageSize );
  1524. if (bUpdExt){
  1525. dwID = MAKELONG(wId, 0);
  1526. }
  1527. if(bExt || bUpdExt)
  1528. dwOverAllSize += PutDWord( &lpNewImage, dwID, &dwNewImageSize );
  1529. else dwOverAllSize += PutWord( &lpNewImage, wId, &dwNewImageSize );
  1530. dwOverAllSize += PutClassName( &lpNewImage, wClassName, &szClassName[0], &dwNewImageSize );
  1531. dwOverAllSize += PutCaptionOrOrd( &lpNewImage, wOrd, &szCaption[0], &dwNewImageSize,
  1532. wClassName, dwStyle );
  1533. if (bExt) {
  1534. dwOverAllSize += PutWord( &lpNewImage, wRawData, &dwNewImageSize );
  1535. while(wRawData) {
  1536. dwOverAllSize += PutByte( &lpNewImage, *((BYTE*)lpRawData++), &dwNewImageSize );
  1537. wRawData--;
  1538. }
  1539. } else
  1540. dwOverAllSize += PutWord( &lpNewImage, 0, &dwNewImageSize );
  1541. // Check if padding is needed
  1542. bPad = (BYTE)Pad4((WORD)(dwOverAllSize-dwPadCalc));
  1543. if (bPad) {
  1544. if( (bPad)<=dwNewImageSize )
  1545. memset( lpNewImage, 0x00, bPad );
  1546. dwNewImageSize -= (bPad);
  1547. dwOverAllSize += (bPad);
  1548. lpNewImage += (bPad);
  1549. }
  1550. }
  1551. if (dwOverAllSize>(LONG)*pdwNewImageSize) {
  1552. // calc the padding as well
  1553. BYTE bPad = (BYTE)Pad4((DWORD)(dwOverAllSize));
  1554. dwOverAllSize += bPad;
  1555. *pdwNewImageSize = dwOverAllSize;
  1556. return uiError;
  1557. }
  1558. *pdwNewImageSize = *pdwNewImageSize-dwNewImageSize;
  1559. if(*pdwNewImageSize>0) {
  1560. // calculate padding
  1561. BYTE bPad = (BYTE)Pad4((DWORD)(*pdwNewImageSize));
  1562. if (bPad>dwNewImageSize) {
  1563. *pdwNewImageSize += bPad;
  1564. return uiError;
  1565. }
  1566. memset(lpNewImage, 0x00, bPad);
  1567. *pdwNewImageSize += bPad;
  1568. }
  1569. return uiError;
  1570. }
  1571. UINT
  1572. ParseMsgTbl( LPVOID lpImageBuf, DWORD dwISize, LPVOID lpBuffer, DWORD dwSize )
  1573. {
  1574. LONG dwOverAllSize = 0L;
  1575. // Should be almost impossible for a Message table to be Huge
  1576. BYTE far * lpImage = (BYTE far *)lpImageBuf;
  1577. LONG dwImageSize = dwISize;
  1578. BYTE far * lpBuf = (BYTE far *)lpBuffer;
  1579. LONG dwBufSize = dwSize;
  1580. BYTE far * lpItem = (BYTE far *)lpBuffer;
  1581. UINT uiOffset = 0;
  1582. LONG lDummy;
  1583. LONG dwRead = 0L;
  1584. ULONG ulNumofBlock = 0l;
  1585. ULONG ulLowId = 0l;
  1586. ULONG ulHighId = 0l;
  1587. ULONG ulOffsetToEntry = 0l;
  1588. USHORT usLength = 0l;
  1589. USHORT usFlags = 0l;
  1590. WORD wPos = 0;
  1591. // Get number of blocks
  1592. GetDWord( &lpImage, &ulNumofBlock, &dwImageSize );
  1593. wPos = 1;
  1594. for( ULONG c = 0; c<ulNumofBlock ; c++) {
  1595. // Get ID of the block
  1596. GetDWord( &lpImage, &ulLowId, &dwImageSize );
  1597. GetDWord( &lpImage, &ulHighId, &dwImageSize );
  1598. // Get the offset to the data
  1599. GetDWord( &lpImage, &ulOffsetToEntry, &dwImageSize );
  1600. BYTE far * lpData = (BYTE far *)lpImageBuf;
  1601. lpData += ulOffsetToEntry;
  1602. while( ulHighId>=ulLowId ) {
  1603. GetMsgStr( &lpData,
  1604. &szCaption[0],
  1605. MAXSTR,
  1606. &usLength,
  1607. &usFlags,
  1608. &dwImageSize );
  1609. // Fixed field
  1610. dwOverAllSize += PutDWord( &lpBuf, 0, &dwBufSize);
  1611. // We don't have the size and pos in a string
  1612. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  1613. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  1614. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  1615. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  1616. // we don't have checksum and style
  1617. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1618. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1619. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1620. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1621. //Put the lowStringId
  1622. //dwOverAllSize += PutDWord( &lpBuf, MAKELONG(ulLowId++, wPos++), &dwBufSize);
  1623. ulLowId++;
  1624. dwOverAllSize += PutDWord( &lpBuf, MAKELONG(wPos, wPos), &dwBufSize);
  1625. wPos++;
  1626. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1627. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1628. // we don't have the language
  1629. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1630. // Put the flags: if 1 = ANSI if 0 = ASCII(OEM)
  1631. dwOverAllSize += PutDWord( &lpBuf, usFlags , &dwBufSize);
  1632. // we don't have the font name
  1633. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  1634. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  1635. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  1636. dwOverAllSize += PutByte( &lpBuf, (BYTE)-1, &dwBufSize);
  1637. dwOverAllSize += PutByte( &lpBuf, (BYTE)-1, &dwBufSize);
  1638. // Let's put null were we don;t have the strings
  1639. uiOffset = sizeof(RESITEM);
  1640. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize); // ClassName
  1641. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize); // FaceName
  1642. dwOverAllSize += PutDWordPtr( &lpBuf, (DWORD_PTR)(lpItem+uiOffset), &dwBufSize); // Caption
  1643. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize); // ResItem
  1644. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize); // TypeItem
  1645. dwOverAllSize += PutStringA( &lpBuf, &szCaption[0], &dwBufSize);
  1646. // Put the size of the resource
  1647. if ((LONG)(dwSize-dwOverAllSize)>=0) {
  1648. uiOffset += strlen((LPSTR)(lpItem+uiOffset))+1;
  1649. // Check if we are alligned
  1650. lDummy = Allign( &lpBuf, &dwBufSize, (LONG)uiOffset);
  1651. dwOverAllSize += lDummy;
  1652. uiOffset += lDummy;
  1653. lDummy = 8;
  1654. PutDWord( &lpItem, (DWORD)uiOffset, &lDummy);
  1655. }
  1656. // Move to the next position
  1657. lpItem = lpBuf;
  1658. // Check if we are at the end and this is just padding
  1659. if (dwImageSize<=16) {
  1660. BYTE bPad = (BYTE)Pad16((DWORD)(dwISize-dwImageSize));
  1661. if (bPad==dwImageSize) {
  1662. BYTE far * lpBuf = lpImage;
  1663. while (bPad){
  1664. if(*lpBuf++!=0x00)
  1665. break;
  1666. bPad--;
  1667. }
  1668. if (bPad==0)
  1669. dwImageSize = -1;
  1670. }
  1671. }
  1672. }
  1673. }
  1674. return (UINT)(dwOverAllSize);
  1675. }
  1676. UINT
  1677. ParseVerst( LPVOID lpImageBuf, DWORD dwISize, LPVOID lpBuffer, DWORD dwSize )
  1678. {
  1679. BYTE far * lpImage = (BYTE far *)lpImageBuf;
  1680. LONG dwImageSize = dwISize;
  1681. BYTE far * lpBuf = (BYTE far *)lpBuffer;
  1682. LONG dwBufSize = dwSize;
  1683. BYTE far * lpItem = (BYTE far *)lpBuffer;
  1684. UINT uiOffset = 0;
  1685. LPRESITEM lpResItem = (LPRESITEM)lpBuffer;
  1686. char far * lpStrBuf = (char far *)(lpBuf+sizeof(RESITEM));
  1687. LONG dwOverAllSize = 0L;
  1688. VER_BLOCK VSBlock;
  1689. WORD wPad = 0;
  1690. WORD wPos = 0;
  1691. while(dwImageSize>0) {
  1692. GetVSBlock( &lpImage, &dwImageSize, &VSBlock );
  1693. TRACE1("Key: %s\t", VSBlock.szKey);
  1694. TRACE1("Value: %s\n", VSBlock.szValue);
  1695. TRACE3("Len: %d\tSkip: %d\tType: %d\n", VSBlock.wBlockLen, VSBlock.wValueLen, VSBlock.wType );
  1696. // check if this is the translation block
  1697. if (!strcmp(VSBlock.szKey, "Translation" )){
  1698. // This is the translation block let the localizer have it for now
  1699. DWORD dwCodeLang = 0;
  1700. LONG lDummy = 4;
  1701. GetDWord( &VSBlock.pValue, &dwCodeLang, &lDummy);
  1702. // Put the value in the string value
  1703. wsprintf( &VSBlock.szValue[0], "%#08lX", dwCodeLang );
  1704. }
  1705. // Fixed field
  1706. dwOverAllSize += PutDWord( &lpBuf, 0, &dwBufSize);
  1707. // We don't have the size and pos in an accelerator
  1708. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  1709. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  1710. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  1711. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  1712. // we don't have checksum and style
  1713. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1714. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1715. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1716. //Put the Flag
  1717. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1718. // we will need to calculate the correct ID for mike
  1719. //Put the Id
  1720. dwOverAllSize += PutDWord( &lpBuf, wPos++, &dwBufSize);
  1721. // we don't have the resID, and the Type Id
  1722. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1723. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1724. // we don't have the language
  1725. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1726. // we don't have the codepage or the font name
  1727. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  1728. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  1729. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  1730. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  1731. dwOverAllSize += PutByte( &lpBuf, (BYTE)-1, &dwBufSize);
  1732. dwOverAllSize += PutByte( &lpBuf, (BYTE)-1, &dwBufSize);
  1733. // Let's put null were we don;t have the strings
  1734. uiOffset = sizeof(RESITEM);
  1735. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize);
  1736. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize);
  1737. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize);
  1738. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize);
  1739. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize);
  1740. lpResItem->lpszClassName = strcpy( lpStrBuf, VSBlock.szKey );
  1741. lpStrBuf += strlen(lpResItem->lpszClassName)+1;
  1742. lpResItem->lpszCaption = strcpy( lpStrBuf, VSBlock.szValue );
  1743. lpStrBuf += strlen(lpResItem->lpszCaption)+1;
  1744. // Put the size of the resource
  1745. if (dwBufSize>0) {
  1746. uiOffset += strlen((LPSTR)(lpResItem->lpszClassName))+1;
  1747. uiOffset += strlen((LPSTR)(lpResItem->lpszCaption))+1;
  1748. }
  1749. // Check if we are alligned
  1750. uiOffset += Allign( (LPLPBYTE)&lpStrBuf, &dwBufSize, (LONG)uiOffset);
  1751. dwOverAllSize += uiOffset-sizeof(RESITEM);
  1752. lpResItem->dwSize = (DWORD)uiOffset;
  1753. // Move to the next position
  1754. lpResItem = (LPRESITEM) lpStrBuf;
  1755. lpBuf = (BYTE far *)lpStrBuf;
  1756. lpStrBuf = (char far *)(lpBuf+sizeof(RESITEM));
  1757. }
  1758. return (UINT)(dwOverAllSize);
  1759. }
  1760. UINT GetVSBlock( BYTE far * far* lplpBuf, LONG* pdwSize, VER_BLOCK* pBlock )
  1761. {
  1762. WORD wPad = 0;
  1763. int iToRead = 0;
  1764. WORD wLen = 0;
  1765. WORD wHead = 0;
  1766. if(*lplpBuf==NULL)
  1767. return 0;
  1768. pBlock->pValue = *lplpBuf;
  1769. wHead = GetWord( lplpBuf, &pBlock->wBlockLen, pdwSize );
  1770. wHead += GetWord( lplpBuf, &pBlock->wValueLen, pdwSize );
  1771. wHead += GetWord( lplpBuf, &pBlock->wType, pdwSize );
  1772. // Get the Key name
  1773. wHead += (WORD)GetStringW( lplpBuf, &pBlock->szKey[0], pdwSize, 100 );
  1774. if(Pad4(wHead))
  1775. wPad += (WORD)SkipByte( lplpBuf, 2, pdwSize );
  1776. iToRead = pBlock->wValueLen;
  1777. pBlock->wHead = wHead;
  1778. // Check if we are going over the image len
  1779. if (iToRead>*pdwSize) {
  1780. // There is an error
  1781. wPad += (WORD)SkipByte( lplpBuf, (UINT)*pdwSize, pdwSize );
  1782. return wHead+wPad;
  1783. }
  1784. // Save the pointer to the Value field
  1785. pBlock->pValue = (pBlock->pValue+wHead+wPad);
  1786. if(pBlock->wType && iToRead){
  1787. iToRead -= wPad>>1;
  1788. // Get the string
  1789. if (iToRead>MAXSTR) {
  1790. *pdwSize -= iToRead*sizeofWord;
  1791. *lplpBuf += iToRead*sizeofWord;
  1792. } else {
  1793. int n = 0;
  1794. int iBytesRead = 0;
  1795. if ((iToRead*sizeofWord)+wHead+wPad>pBlock->wBlockLen)
  1796. // Need to fix this up. Bug in the RC compiler?
  1797. iToRead -= ((iToRead*sizeofWord)+wHead+wPad - pBlock->wBlockLen)>>1;
  1798. iBytesRead = GetStringW(lplpBuf, &pBlock->szValue[0], pdwSize, 256);
  1799. //
  1800. // Some old version stamp has a NULL char in between
  1801. // Microsoft Corp. and the year of copyright. GetString
  1802. // will return the number of byte read up to the NULL char.
  1803. // We need to skip the rest.
  1804. //
  1805. if (iBytesRead < iToRead*sizeofWord)
  1806. {
  1807. iBytesRead += SkipByte(lplpBuf,
  1808. iToRead*sizeofWord-iBytesRead,
  1809. pdwSize);
  1810. }
  1811. iToRead = iBytesRead;
  1812. }
  1813. } else {
  1814. SkipByte( lplpBuf, iToRead, pdwSize );
  1815. *pBlock->szValue = '\0';
  1816. }
  1817. if (*pdwSize)
  1818. {
  1819. WORD far * lpw = (WORD far *)*lplpBuf;
  1820. while((WORD)*(lpw)==0x0000)
  1821. {
  1822. wPad += (WORD)SkipByte( (BYTE far * far *)&lpw, 2, pdwSize );
  1823. if ((*pdwSize)<=0)
  1824. {
  1825. break;
  1826. }
  1827. }
  1828. *lplpBuf = (BYTE far *)lpw;
  1829. }
  1830. return (wHead+iToRead+wPad);
  1831. }
  1832. UINT
  1833. PutVSBlock( BYTE far * far * lplpImage, LONG* pdwSize, VER_BLOCK ver,
  1834. LPSTR lpStr, BYTE far * far * lplpBlockSize, WORD* pwTrash)
  1835. {
  1836. // We have to write the info in the VER_BLOCK in the new image
  1837. // We want to remember were the block size field is so we can update it later
  1838. WORD wHead = 0;
  1839. WORD wValue = 0;
  1840. WORD wPad = Pad4(ver.wHead);
  1841. *pwTrash = 0;
  1842. // Get the pointer to the header of the block
  1843. BYTE far * pHead = ver.pValue-ver.wHead-wPad;
  1844. BYTE far * lpNewImage = *lplpImage;
  1845. // Copy the header of the block to the new image
  1846. wHead = ver.wHead;
  1847. if (*pdwSize>=(int)ver.wHead) {
  1848. memcpy( *lplpImage, pHead, ver.wHead );
  1849. *pdwSize -= ver.wHead;
  1850. lpNewImage += ver.wHead;
  1851. }
  1852. // Check if padding is needed
  1853. if ((wPad) && (*pdwSize>=(int)wPad)) {
  1854. memset( *lplpImage+ver.wHead, 0, wPad );
  1855. *pdwSize -= wPad;
  1856. lpNewImage += wPad;
  1857. }
  1858. // Store the pointer to the block size WORD
  1859. BYTE far * pBlockSize = *lplpImage;
  1860. // Check if the value is a string or a BYTE array
  1861. if(ver.wType) {
  1862. // it is a string, copy the updated item
  1863. // Check if we had a string in this field
  1864. if(ver.wValueLen) {
  1865. BYTE far * lpImageStr = *lplpImage+wHead+wPad;
  1866. wValue = (WORD)PutStringW(&lpImageStr, lpStr, pdwSize);
  1867. lpNewImage += wValue;
  1868. // Check if padding is needed
  1869. if ((Pad4(wValue)) && (*pdwSize>=(int)Pad4(wValue))) {
  1870. memset( *lplpImage+ver.wHead+wValue+wPad, 0, Pad4(wValue) );
  1871. *pdwSize -= Pad4(wValue);
  1872. lpNewImage += Pad4(wValue);
  1873. }
  1874. WORD wPad1 = Pad4(wValue);
  1875. WORD wFixUp = wValue/sizeofWord;
  1876. *pwTrash = Pad4(ver.wValueLen);
  1877. wValue += wPad1;
  1878. // Fix to the strange behaviour of the ver.dll
  1879. if((wPad1) && (wPad1>=*pwTrash)) {
  1880. wValue -= *pwTrash;
  1881. } else *pwTrash = 0;
  1882. // Fix up the Value len field. We will put the len of the value without padding
  1883. // The len will be in char so since the string is unicode will be twice the size
  1884. memcpy( pBlockSize+2, &wFixUp, 2);
  1885. }
  1886. } else {
  1887. // it is an array, just copy it in the new image buffer
  1888. wValue = ver.wValueLen;
  1889. if (*pdwSize>=(int)ver.wValueLen) {
  1890. memcpy(*lplpImage+wHead+wPad, ver.pValue, ver.wValueLen);
  1891. *pdwSize -= ver.wValueLen;
  1892. lpNewImage += ver.wValueLen;
  1893. }
  1894. // Check if padding is needed
  1895. if ((Pad4(ver.wValueLen)) && (*pdwSize>=(int)Pad4(ver.wValueLen))) {
  1896. memset( *lplpImage+ver.wHead+ver.wValueLen+wPad, 0, Pad4(ver.wValueLen) );
  1897. *pdwSize -= Pad4(ver.wValueLen);
  1898. lpNewImage += Pad4(ver.wValueLen);
  1899. }
  1900. wPad += Pad4(ver.wValueLen);
  1901. }
  1902. *lplpBlockSize = pBlockSize;
  1903. *lplpImage = lpNewImage;
  1904. return wPad+wValue+wHead;
  1905. }
  1906. /*
  1907. * Will return the matching LPRESITEM
  1908. */
  1909. LPRESITEM
  1910. GetItem( BYTE far * lpBuf, LONG dwNewSize, LPSTR lpStr )
  1911. {
  1912. LPRESITEM lpResItem = (LPRESITEM) lpBuf;
  1913. while(strcmp(lpResItem->lpszClassName, lpStr)) {
  1914. lpBuf += lpResItem->dwSize;
  1915. dwNewSize -= lpResItem->dwSize;
  1916. if (dwNewSize<=0)
  1917. return LPNULL;
  1918. lpResItem = (LPRESITEM) lpBuf;
  1919. }
  1920. return lpResItem;
  1921. }
  1922. UINT
  1923. UpdateVerst( LPVOID lpNewBuf, LONG dwNewSize,
  1924. LPVOID lpOldI, LONG dwOldImageSize,
  1925. LPVOID lpNewI, DWORD* pdwNewImageSize )
  1926. {
  1927. /*
  1928. * This Function is a big mess. It is like this because the RC compiler generate
  1929. * some inconsistent code so we have to do a lot of hacking to get the VS working
  1930. * In future, if ever ver.dll and the RC compiler will be fixed will be possible
  1931. * fix some of the bad thing we have to do to get the updated VS as consistent as
  1932. * possible with the old one
  1933. */
  1934. UINT uiError = ERROR_NO_ERROR;
  1935. LONG dwNewImageSize = *pdwNewImageSize;
  1936. BYTE far * lpNewImage = (BYTE far *) lpNewI;
  1937. BYTE far * lpOldImage = (BYTE far *) lpOldI;
  1938. BYTE far * lpBuf = (BYTE far *) lpNewBuf;
  1939. LPRESITEM lpResItem = LPNULL;
  1940. WORD wPos = 0;
  1941. // Updated info
  1942. WORD wUpdPos = 0;
  1943. char szCaption[300];
  1944. char szUpdCaption[300];
  1945. char szUpdKey[100];
  1946. DWORD dwOriginalOldSize = dwOldImageSize;
  1947. LONG dwOverAllSize = 0l;
  1948. WORD wPad = 0;
  1949. // Pointer to the block size to fix up later
  1950. BYTE far * lpVerBlockSize = LPNULL;
  1951. BYTE far * lpSFIBlockSize = LPNULL;
  1952. BYTE far * lpTrnBlockSize = LPNULL;
  1953. BYTE far * lpStrBlockSize = LPNULL;
  1954. BYTE far * lpTrnBlockName = LPNULL;
  1955. BYTE far * lpDummy = LPNULL;
  1956. LONG dwDummySize;
  1957. WORD wVerBlockSize = 0;
  1958. WORD wSFIBlockSize = 0;
  1959. WORD wTrnBlockSize = 0;
  1960. WORD wStrBlockSize = 0;
  1961. WORD wTrash = 0; // we need this to fix a bug in the RC compiler
  1962. WORD wDefaultLang = 0x0409;
  1963. // StringFileInfo
  1964. VER_BLOCK SFI; // StringFileInfo
  1965. LONG lSFILen = 0;
  1966. // Translation blocks
  1967. VER_BLOCK Trn;
  1968. LONG lTrnLen = 0;
  1969. BOOL bHasTranslation=(NULL != GetItem( lpBuf, dwNewSize, "Translation"));
  1970. BOOL bTrnBlockFilled=FALSE;
  1971. VER_BLOCK Str; // Strings
  1972. // we read first of all the information from the VS_VERSION_INFO block
  1973. VER_BLOCK VS_INFO; // VS_VERSION_INFO
  1974. int iHeadLen = GetVSBlock( &lpOldImage, &dwOldImageSize, &VS_INFO );
  1975. // Write the block in the new image
  1976. wVerBlockSize = (WORD)PutVSBlock( &lpNewImage, &dwNewImageSize, VS_INFO,
  1977. &VS_INFO.szValue[0], &lpVerBlockSize, &wTrash );
  1978. dwOverAllSize = wVerBlockSize+wTrash;
  1979. LONG lVS_INFOLen = VS_INFO.wBlockLen - iHeadLen;
  1980. while(dwOldImageSize>0) {
  1981. //Get the StringFileInfo
  1982. iHeadLen = GetVSBlock( &lpOldImage, &dwOldImageSize, &SFI );
  1983. // Check if this is the StringFileInfo field
  1984. if (!strcmp(SFI.szKey, "StringFileInfo")) {
  1985. bTrnBlockFilled=TRUE;
  1986. // Read all the translation blocks
  1987. lSFILen = SFI.wBlockLen-iHeadLen;
  1988. // Write the block in the new image
  1989. wSFIBlockSize = (WORD)PutVSBlock( &lpNewImage, &dwNewImageSize, SFI,
  1990. &SFI.szValue[0], &lpSFIBlockSize, &wTrash );
  1991. dwOverAllSize += wSFIBlockSize+wTrash;
  1992. while(lSFILen>0) {
  1993. // Read the Translation block
  1994. iHeadLen = GetVSBlock( &lpOldImage, &dwOldImageSize, &Trn );
  1995. // Calculate the right key name
  1996. if ((lpResItem = GetItem( lpBuf, dwNewSize, Trn.szKey)) && bHasTranslation) {
  1997. // We default to UNICODE for the 32 bit files
  1998. WORD wLang;
  1999. if(lpResItem)
  2000. {
  2001. if (lpResItem->dwLanguage != 0xffffffff)
  2002. {
  2003. wLang = LOWORD(lpResItem->dwLanguage);
  2004. }
  2005. else
  2006. {
  2007. wLang = wDefaultLang;
  2008. }
  2009. }
  2010. GenerateTransField( wLang, &Trn );
  2011. // Save the position for later Fixup
  2012. lpTrnBlockName = lpNewImage;
  2013. }
  2014. // Write the block in the new image
  2015. wTrnBlockSize = (WORD)PutVSBlock( &lpNewImage, &dwNewImageSize, Trn,
  2016. &Trn.szValue[0], &lpTrnBlockSize, &wTrash );
  2017. dwOverAllSize += wTrnBlockSize+wTrash;
  2018. lTrnLen = Trn.wBlockLen-iHeadLen;
  2019. while(lTrnLen>0) {
  2020. // Read the Strings in the block
  2021. iHeadLen = GetVSBlock( &lpOldImage, &dwOldImageSize, &Str );
  2022. lTrnLen -= iHeadLen;
  2023. TRACE2("Key: %s\tValue: %s\n", Str.szKey, Str.szValue );
  2024. TRACE3("Len: %d\tValLen: %d\tType: %d\n", Str.wBlockLen, Str.wValueLen, Str.wType );
  2025. strcpy(szCaption, Str.szValue);
  2026. // Check if this Item has been updated
  2027. if ((lpResItem = GetItem( lpBuf, dwNewSize, Str.szKey))) {
  2028. strcpy( szUpdCaption, lpResItem->lpszCaption );
  2029. strcpy( szUpdKey, lpResItem->lpszClassName );
  2030. }
  2031. if (!strcmp( szUpdKey, Str.szKey)) {
  2032. strcpy( szCaption, szUpdCaption );
  2033. wUpdPos = 0;
  2034. }
  2035. // Write the block in the new image
  2036. wStrBlockSize = (WORD)PutVSBlock( &lpNewImage, &dwNewImageSize, Str,
  2037. szCaption, &lpStrBlockSize, &wTrash );
  2038. dwOverAllSize += wStrBlockSize+wTrash;
  2039. // Fix up the size of the block
  2040. if (dwNewImageSize>=0)
  2041. memcpy( lpStrBlockSize, &wStrBlockSize, 2);
  2042. wTrnBlockSize += wStrBlockSize + wTrash;
  2043. }
  2044. lSFILen -= Trn.wBlockLen;
  2045. // Fix up the size of the block
  2046. if (dwNewImageSize>=0)
  2047. memcpy( lpTrnBlockSize, &wTrnBlockSize, 2);
  2048. wSFIBlockSize += wTrnBlockSize;
  2049. }
  2050. lVS_INFOLen -= SFI.wBlockLen;
  2051. // Fix up the size of the block
  2052. if (dwNewImageSize>=0)
  2053. memcpy( lpSFIBlockSize, &wSFIBlockSize, 2);
  2054. wVerBlockSize += wSFIBlockSize;
  2055. } else {
  2056. // this is another block skip it all
  2057. lVS_INFOLen -= SFI.wValueLen+iHeadLen;
  2058. // Check if this block is the translation field
  2059. if (!strcmp(SFI.szKey, "Translation")) {
  2060. // it is calculate the right value to place in the value field
  2061. // We calculate automatically the value to have the correct
  2062. // localized language in the translation field
  2063. //wVerBlockSize += PutTranslation( &lpNewImage, &dwNewImageSize, SFI );
  2064. // check if this is the translation block
  2065. // This is the translation block let the localizer have it for now
  2066. //
  2067. // We do generate the Tranlsation filed from the language
  2068. // We will have to update the block name as well
  2069. //
  2070. DWORD dwCodeLang = 0;
  2071. if ((lpResItem = GetItem( lpBuf, dwNewSize, SFI.szKey)))
  2072. {
  2073. WORD wLang = 0x0409;
  2074. if(lpResItem)
  2075. wLang = (LOWORD(lpResItem->dwLanguage)!=0xffff ? LOWORD(lpResItem->dwLanguage) : 0x0409);
  2076. dwCodeLang = GenerateTransField(wLang, FALSE);
  2077. if (bTrnBlockFilled)
  2078. {
  2079. // fix up the block name
  2080. GenerateTransField( wLang, &Trn );
  2081. // Write the block in the new image
  2082. dwDummySize = dwNewImageSize;
  2083. PutVSBlock( &lpTrnBlockName, &dwDummySize, Trn,
  2084. &Trn.szValue[0], &lpDummy, &wTrash );
  2085. // Fix up the block size
  2086. memcpy( lpTrnBlockSize, &wTrnBlockSize, 2);
  2087. }
  2088. else
  2089. {
  2090. wDefaultLang = LOWORD(dwCodeLang);
  2091. }
  2092. } else {
  2093. // Place the original value here
  2094. dwCodeLang =(DWORD)*(SFI.pValue);
  2095. }
  2096. LONG lDummy = 4;
  2097. SFI.pValue -= PutDWord( &SFI.pValue, dwCodeLang, &lDummy );
  2098. }
  2099. // Write the block in the new image
  2100. wVerBlockSize += (WORD)PutVSBlock( &lpNewImage, &dwNewImageSize, SFI,
  2101. &SFI.szValue[0], &lpDummy, &wTrash );
  2102. if (dwNewImageSize>=0)
  2103. memcpy( lpVerBlockSize, &wVerBlockSize, 2);
  2104. dwOverAllSize = wVerBlockSize+wTrash;
  2105. }
  2106. }
  2107. // fix up the block size
  2108. if (dwNewImageSize>=0)
  2109. memcpy( lpVerBlockSize, &wVerBlockSize, 2);
  2110. if (dwOverAllSize>(LONG)*pdwNewImageSize) {
  2111. // calc the padding as well
  2112. BYTE bPad = (BYTE)Pad16((DWORD)(dwOverAllSize));
  2113. dwOverAllSize += bPad;
  2114. *pdwNewImageSize = dwOverAllSize;
  2115. return uiError;
  2116. }
  2117. *pdwNewImageSize = *pdwNewImageSize-dwNewImageSize;
  2118. if(*pdwNewImageSize>0) {
  2119. // calculate padding
  2120. BYTE bPad = (BYTE)Pad16((DWORD)(*pdwNewImageSize));
  2121. if (bPad>dwNewImageSize) {
  2122. *pdwNewImageSize += bPad;
  2123. return uiError;
  2124. }
  2125. memset(lpNewImage, 0x00, bPad);
  2126. *pdwNewImageSize += bPad;
  2127. }
  2128. return uiError;
  2129. }
  2130. UINT GetStringU( PWCHAR pwStr, LPSTR pszStr )
  2131. {
  2132. PWCHAR pwStart = pwStr;
  2133. while (*pwStr!=0x0000) {
  2134. *(pszStr++) = LOBYTE(*(pwStr++));
  2135. }
  2136. *(pszStr++) = LOBYTE(*(pwStr++));
  2137. return (UINT)(pwStr-pwStart);
  2138. }
  2139. UINT
  2140. SkipByte( BYTE far * far * lplpBuf, UINT uiSkip, LONG* pdwSize )
  2141. {
  2142. if(*pdwSize>=(int)uiSkip) {
  2143. *lplpBuf += uiSkip;;
  2144. *pdwSize -= uiSkip;
  2145. }
  2146. return uiSkip;
  2147. }
  2148. BYTE
  2149. GetDWord( BYTE far * far* lplpBuf, DWORD* dwValue, LONG* pdwSize )
  2150. {
  2151. if (*pdwSize>=sizeofDWord){
  2152. memcpy( dwValue, *lplpBuf, sizeofDWord);
  2153. *lplpBuf += sizeofDWord;
  2154. *pdwSize -= sizeofDWord;
  2155. } else *dwValue = 0;
  2156. return sizeofDWord;
  2157. }
  2158. BYTE
  2159. GetWord( BYTE far * far* lplpBuf, WORD* wValue, LONG* pdwSize )
  2160. {
  2161. if (*pdwSize>=sizeofWord){
  2162. memcpy( wValue, *lplpBuf, sizeofWord);
  2163. *lplpBuf += sizeofWord;
  2164. *pdwSize -= sizeofWord;
  2165. } else *wValue = 0;
  2166. return sizeofWord;
  2167. }
  2168. BYTE
  2169. GetByte( BYTE far * far* lplpBuf, BYTE* bValue, LONG* pdwSize )
  2170. {
  2171. if (*pdwSize>=sizeofByte){
  2172. memcpy(bValue, *lplpBuf, sizeofByte);
  2173. *lplpBuf += sizeofByte;
  2174. *pdwSize -= sizeofByte;
  2175. } else *bValue = 0;
  2176. return sizeofByte;
  2177. }
  2178. UINT
  2179. GetStringW( BYTE far * far* lplpBuf, LPSTR lpszText, LONG* pdwSize, WORD cLen )
  2180. {
  2181. if(*lplpBuf==NULL)
  2182. return 0;
  2183. int cch = _WCSLEN((WCHAR*)*lplpBuf);
  2184. if (*pdwSize>=cch){
  2185. _WCSTOMBS( lpszText, (WCHAR*)*lplpBuf, cLen );
  2186. *lplpBuf += (cch*sizeofWord);
  2187. *pdwSize -= (cch*sizeofWord);
  2188. } else *lplpBuf = '\0';
  2189. return(cch*2);
  2190. }
  2191. UINT
  2192. GetStringA( BYTE far * far* lplpBuf, LPSTR lpszText, LONG* pdwSize )
  2193. {
  2194. if(*lplpBuf==NULL)
  2195. return 0;
  2196. int iSize = strlen((char*)*lplpBuf)+1;
  2197. if (*pdwSize>=iSize){
  2198. memcpy( lpszText, *lplpBuf, iSize);
  2199. *lplpBuf += iSize;
  2200. *pdwSize -= iSize;
  2201. } else *lplpBuf = '\0';
  2202. return iSize;
  2203. }
  2204. UINT
  2205. GetPascalString( BYTE far * far* lplpBuf, LPSTR lpszText, WORD wMaxLen, LONG* pdwSize )
  2206. {
  2207. // Get the length of the string
  2208. WORD wstrlen = 0;
  2209. WORD wMBLen = 0;
  2210. GetWord( lplpBuf, &wstrlen, pdwSize );
  2211. if ((wstrlen+1)>wMaxLen) {
  2212. *pdwSize -= wstrlen*2;
  2213. *lplpBuf += wstrlen*2;
  2214. } else {
  2215. if (wstrlen) {
  2216. WCHAR* lpwszStr = new WCHAR[wstrlen+1];
  2217. if (!lpwszStr)
  2218. *pdwSize =-1;
  2219. else {
  2220. memcpy(lpwszStr, *lplpBuf, (wstrlen*2));
  2221. *(lpwszStr+wstrlen) = 0;
  2222. if(lstrlenW(lpwszStr) < wstrlen)
  2223. {
  2224. // We have at least one \0 in the string.
  2225. // This is done to convert \0 in the string in to \\0
  2226. // First pass check how many \0 we have
  2227. int c = wstrlen;
  2228. int czero = 0;
  2229. while(c)
  2230. {
  2231. c--;
  2232. if((WORD)*(lpwszStr+c)==0)
  2233. {
  2234. czero++;
  2235. }
  2236. }
  2237. // Now that we have the size reallocate the buffer
  2238. delete lpwszStr;
  2239. if ((wstrlen+czero*_NULL_TAG_LEN_+1)>wMaxLen) {
  2240. *pdwSize -= wstrlen*2;
  2241. *lplpBuf += wstrlen*2;
  2242. }
  2243. else {
  2244. WCHAR* lpwszStr = new WCHAR[wstrlen+czero*_NULL_TAG_LEN_+1];
  2245. if (!lpwszStr)
  2246. *pdwSize =-1;
  2247. else {
  2248. int clen = 0;
  2249. c = 0;
  2250. WCHAR* lpwStr = (WCHAR*)*lplpBuf;
  2251. WCHAR* lpwStrW = lpwszStr;
  2252. while(c<wstrlen)
  2253. {
  2254. if((WORD)*(lpwStr+c)==0)
  2255. {
  2256. memcpy(lpwStrW, _W_RLT_NULL_, (_NULL_TAG_LEN_*2));
  2257. lpwStrW += _NULL_TAG_LEN_;
  2258. clen += _NULL_TAG_LEN_-1;
  2259. }
  2260. else
  2261. *lpwStrW++ = *(lpwStr+c);
  2262. clen++;
  2263. c++;
  2264. }
  2265. *(lpwszStr+clen) = 0;
  2266. wMBLen = (WORD)_WCSTOMBS( lpszText, (WCHAR*)lpwszStr, wMaxLen);
  2267. delete lpwszStr;
  2268. }
  2269. }
  2270. }
  2271. else
  2272. {
  2273. wMBLen = (WORD)_WCSTOMBS( lpszText, (WCHAR*)lpwszStr, wMaxLen);
  2274. delete lpwszStr;
  2275. }
  2276. }
  2277. }
  2278. *(lpszText+wMBLen) = 0;
  2279. *lplpBuf += wstrlen*2;
  2280. *pdwSize -= wstrlen*2;
  2281. }
  2282. return(wstrlen+1);
  2283. }
  2284. UINT
  2285. PutMsgStr( BYTE far * far* lplpBuf, LPSTR lpszText, WORD wFlags, LONG* pdwSize )
  2286. {
  2287. // Put the length of the entry
  2288. UINT uiLen = strlen(lpszText)+1;
  2289. //for unicode string;
  2290. WCHAR* lpwszStr = new WCHAR[uiLen*2];
  2291. if(wFlags && uiLen)
  2292. uiLen = _MBSTOWCS(lpwszStr, lpszText, uiLen*sizeofWord)*sizeofWord;
  2293. UINT uiPad = Pad4(uiLen);
  2294. UINT uiWrite = PutWord(lplpBuf, (WORD) uiLen+4+uiPad, pdwSize);
  2295. // Write the flag
  2296. uiWrite += PutWord(lplpBuf, wFlags, pdwSize);
  2297. // Write the string
  2298. if (*pdwSize>=(int) uiLen)
  2299. if (uiLen){
  2300. if (wFlags)
  2301. memcpy(*lplpBuf, lpwszStr, uiLen);
  2302. else
  2303. memcpy(*lplpBuf, lpszText, uiLen);
  2304. *lplpBuf += uiLen;
  2305. *pdwSize -= uiLen;
  2306. uiWrite += uiLen;
  2307. }
  2308. else
  2309. *pdwSize = -1;
  2310. // Padding
  2311. while(uiPad) {
  2312. uiWrite += PutByte(lplpBuf, 0, pdwSize);
  2313. uiPad--;
  2314. }
  2315. delete lpwszStr;
  2316. return uiWrite;
  2317. }
  2318. UINT
  2319. GetMsgStr( BYTE far * far* lplpBuf, LPSTR lpszText, WORD wMaxLen, WORD* pwLen, WORD* pwFlags, LONG* pdwSize )
  2320. {
  2321. // Get the length of the entry
  2322. UINT uiRead = GetWord( lplpBuf, pwLen, pdwSize );
  2323. // Get the flag
  2324. uiRead += GetWord( lplpBuf, pwFlags, pdwSize );
  2325. if (!*pwLen)
  2326. return 0;
  2327. // If flags=1 then the string is a unicode str else is ASCII
  2328. // Bug #354 We cannot assume the string is NULL terminated.
  2329. // There is no specification if the string is a NULL terminated string but since
  2330. // the doc say that the format is similar to the stringtable then
  2331. // we have to assume the string is not NULL terminated
  2332. WORD wstrlen = *pwLen-4; // Get the len of the entry and subtract 4 (len + flag)
  2333. WORD wMBLen = 0;
  2334. if ((wstrlen+1)>wMaxLen) {
  2335. } else {
  2336. if (wstrlen && *pwFlags) {
  2337. wMBLen = (WORD)_WCSTOMBS( lpszText, (WCHAR*)*lplpBuf, wMaxLen );
  2338. } else memcpy( lpszText, (char*)*lplpBuf, wstrlen );
  2339. *(lpszText+(wstrlen)) = 0;
  2340. TRACE1("Caption: %Fs\n", (wstrlen<256 ? lpszText : "\n"));
  2341. }
  2342. *lplpBuf += *pwLen-uiRead;
  2343. *pdwSize -= *pwLen-uiRead;
  2344. return(wstrlen);
  2345. }
  2346. UINT
  2347. GetNameOrOrd( BYTE far * far* lplpBuf, WORD* wOrd, LPSTR lpszText, LONG* pdwSize )
  2348. {
  2349. UINT uiSize = 0;
  2350. if(*lplpBuf==NULL)
  2351. return 0;
  2352. *wOrd = (WORD)(((**lplpBuf)<<8)+(*(*lplpBuf+1)));
  2353. if((*wOrd)==0xFFFF) {
  2354. // This is an Ordinal
  2355. uiSize += GetWord( lplpBuf, wOrd, pdwSize );
  2356. uiSize += GetWord( lplpBuf, wOrd, pdwSize );
  2357. *lpszText = '\0';
  2358. } else {
  2359. uiSize += GetStringW( lplpBuf, lpszText, pdwSize, 128 );
  2360. *wOrd = 0;
  2361. }
  2362. return uiSize;
  2363. }
  2364. UINT
  2365. GetCaptionOrOrd( BYTE far * far* lplpBuf, WORD* wOrd, LPSTR lpszText, LONG* pdwSize,
  2366. WORD wClass, DWORD dwStyle )
  2367. {
  2368. UINT uiSize = 0;
  2369. if(*lplpBuf==NULL)
  2370. return 0;
  2371. *wOrd = (WORD)(((**lplpBuf)<<8)+(*(*lplpBuf+1)));
  2372. if((*wOrd)==0xFFFF) {
  2373. // This is an Ordinal
  2374. uiSize += GetWord( lplpBuf, wOrd, pdwSize );
  2375. uiSize += GetWord( lplpBuf, wOrd, pdwSize );
  2376. *lpszText = '\0';
  2377. } else {
  2378. uiSize += GetStringW( lplpBuf, lpszText, pdwSize, MAXSTR );
  2379. *wOrd = 0;
  2380. }
  2381. return uiSize;
  2382. }
  2383. UINT
  2384. GetClassName( BYTE far * far* lplpBuf, WORD* wClass, LPSTR lpszText, LONG* pdwSize )
  2385. {
  2386. UINT uiSize = 0;
  2387. if(*lplpBuf==NULL)
  2388. return 0;
  2389. *wClass = (WORD)(((**lplpBuf)<<8)+(*(*lplpBuf+1)));
  2390. if( *wClass==0xFFFF ) {
  2391. // This is an Ordinal
  2392. uiSize += GetWord( lplpBuf, wClass, pdwSize );
  2393. uiSize += GetWord( lplpBuf, wClass, pdwSize );
  2394. *lpszText = '\0';
  2395. } else {
  2396. uiSize += GetStringW( lplpBuf, lpszText, pdwSize, 128 );
  2397. *wClass = 0;
  2398. }
  2399. return uiSize;
  2400. }
  2401. LONG ReadFile(CFile* pFile, UCHAR * pBuf, LONG lRead)
  2402. {
  2403. LONG lLeft = lRead;
  2404. WORD wRead = 0;
  2405. DWORD dwOffset = 0;
  2406. while(lLeft>0){
  2407. wRead =(WORD) (32738ul < lLeft ? 32738: lLeft);
  2408. if (wRead!=_lread( (HFILE)pFile->m_hFile, (UCHAR *)pBuf+dwOffset, wRead))
  2409. return 0l;
  2410. lLeft -= wRead;
  2411. dwOffset += wRead;
  2412. }
  2413. return dwOffset;
  2414. }
  2415. UINT CopyFile( CFile* pfilein, CFile* pfileout )
  2416. {
  2417. LONG lLeft = pfilein->GetLength();
  2418. WORD wRead = 0;
  2419. DWORD dwOffset = 0;
  2420. BYTE far * pBuf = (BYTE far *) new BYTE[32739];
  2421. if(!pBuf)
  2422. return ERROR_NEW_FAILED;
  2423. while(lLeft>0){
  2424. wRead =(WORD) (32738ul < lLeft ? 32738: lLeft);
  2425. if (wRead!= pfilein->Read( pBuf, wRead))
  2426. return ERROR_FILE_READ;
  2427. pfileout->Write( pBuf, wRead );
  2428. lLeft -= wRead;
  2429. dwOffset += wRead;
  2430. }
  2431. delete []pBuf;
  2432. return ERROR_NO_ERROR;
  2433. }
  2434. UINT GetRes(
  2435. BYTE far * far* lplpBuffer,
  2436. UINT* puiBufSize,
  2437. WORD* wTypeId, LPSTR lplpszTypeId,
  2438. WORD* wNameId, LPSTR lplpszNameId,
  2439. DWORD* dwLang, DWORD* dwSize, DWORD* dwFileOffset )
  2440. {
  2441. UINT uiSize = 0l;
  2442. LONG lSize = *puiBufSize;
  2443. uiSize = GetWord( lplpBuffer, wTypeId, (LONG*)&lSize );
  2444. uiSize += GetStringA( lplpBuffer, lplpszTypeId, (LONG*)&lSize );
  2445. uiSize += SkipByte( lplpBuffer, Pad4(uiSize), (LONG*)&lSize );
  2446. uiSize += GetWord( lplpBuffer, wNameId, (LONG*)&lSize );
  2447. uiSize += GetStringA( lplpBuffer, lplpszNameId, (LONG*)&lSize );
  2448. uiSize += SkipByte( lplpBuffer, Pad4(uiSize), (LONG*)&lSize );
  2449. uiSize += GetDWord( lplpBuffer, dwLang, (LONG*)&lSize );
  2450. uiSize += GetDWord( lplpBuffer, dwSize, (LONG*)&lSize );
  2451. uiSize += GetDWord( lplpBuffer, dwFileOffset, (LONG*)&lSize );
  2452. *puiBufSize = lSize;
  2453. return uiSize;
  2454. }
  2455. UINT GetUpdatedRes(
  2456. BYTE far * far* lplpBuffer,
  2457. UINT* puiBufSize,
  2458. WORD* wTypeId, LPSTR lplpszTypeId,
  2459. WORD* wNameId, LPSTR lplpszNameId,
  2460. DWORD* dwLang, DWORD* dwSize )
  2461. {
  2462. UINT uiSize = 0l;
  2463. LONG lSize = *puiBufSize;
  2464. uiSize = GetWord( lplpBuffer, wTypeId, (LONG*)&lSize );
  2465. uiSize += GetStringA( lplpBuffer, lplpszTypeId, (LONG*)&lSize );
  2466. uiSize += SkipByte( lplpBuffer, Pad4(uiSize), (LONG*)&lSize );
  2467. uiSize += GetWord( lplpBuffer, wNameId, (LONG*)&lSize );
  2468. uiSize += GetStringA( lplpBuffer, lplpszNameId, (LONG*)&lSize );
  2469. uiSize += SkipByte( lplpBuffer, Pad4(uiSize), (LONG*)&lSize );
  2470. uiSize += GetDWord( lplpBuffer, dwLang, (LONG*)&lSize );
  2471. uiSize += GetDWord( lplpBuffer, dwSize, (LONG*)&lSize );
  2472. *puiBufSize = lSize;
  2473. return 0;
  2474. }
  2475. UINT
  2476. PutClassName( BYTE far * far* lplpBuf, WORD wClass, LPSTR lpszText, LONG* pdwSize )
  2477. {
  2478. UINT uiSize = 0;
  2479. if( (wClass==0x0080) ||
  2480. (wClass==0x0081) ||
  2481. (wClass==0x0082) ||
  2482. (wClass==0x0083) ||
  2483. (wClass==0x0084) ||
  2484. (wClass==0x0085)
  2485. ) {
  2486. // This is an Ordinal
  2487. uiSize += PutWord(lplpBuf, 0xFFFF, pdwSize);
  2488. uiSize += PutWord(lplpBuf, wClass, pdwSize);
  2489. } else {
  2490. uiSize += PutStringW(lplpBuf, lpszText, pdwSize);
  2491. }
  2492. return uiSize;
  2493. }
  2494. UINT
  2495. PutPascalStringW( BYTE far * far* lplpBuf, LPSTR lpszText, WORD wLen, LONG* pdwSize )
  2496. {
  2497. UINT uiSize = 0;
  2498. WCHAR * pWStrBuf = (WCHAR*)&wszUpdCaption;
  2499. // calculate the necessary lenght
  2500. WORD wWCLen = (WORD)_MBSTOWCS( pWStrBuf, lpszText, 0 );
  2501. if(wWCLen>MAXSTR)
  2502. {
  2503. // Allocate a new buffer
  2504. pWStrBuf = new WCHAR[wWCLen+1];
  2505. }
  2506. WCHAR * pWStr = pWStrBuf;
  2507. // convert the string for good
  2508. wLen = _MBSTOWCS( pWStr, lpszText, wWCLen )-1;
  2509. WCHAR * wlpRltNull = pWStr;
  2510. WCHAR * wlpStrEnd = pWStr+wLen;
  2511. // First of all check for _RLT32_NULL_ tag
  2512. while((wlpRltNull = wcsstr(wlpRltNull, _W_RLT_NULL_)) && (wlpStrEnd>=wlpRltNull))
  2513. {
  2514. // remove the null tag and place \0
  2515. *wlpRltNull++ = 0x0000;
  2516. wlpRltNull = (WCHAR*)memmove(wlpRltNull, wlpRltNull+_NULL_TAG_LEN_-1, (short)(wlpStrEnd-(wlpRltNull+_NULL_TAG_LEN_-1))*2 );
  2517. wlpStrEnd -= (_NULL_TAG_LEN_-1);
  2518. }
  2519. wLen = (WORD)(wlpStrEnd-pWStr);
  2520. // We will use the buffer provided by the szUpdCaption string to calculate
  2521. // the necessary lenght
  2522. //wWCLen = _MBSTOWCS( (WCHAR*)&szUpdCaption, lpszText, 0 ) - 1;
  2523. //if (wWCLen>1)
  2524. // wLen = wWCLen;
  2525. uiSize = PutWord( lplpBuf, wLen, pdwSize );
  2526. if (*pdwSize>=(int)(wLen*2)){
  2527. if(wLen) {
  2528. //wLen = _MBSTOWCS( (WCHAR*)*lplpBuf, lpszText, wWCLen );
  2529. memcpy(*lplpBuf, pWStr, wLen*2);
  2530. }
  2531. *lplpBuf += wLen*2;
  2532. *pdwSize -= wLen*2;
  2533. } else *pdwSize = -1;
  2534. if(pWStrBuf!=(WCHAR*)&wszUpdCaption)
  2535. delete pWStrBuf;
  2536. return uiSize+(wWCLen*2);
  2537. }
  2538. void GenerateTransField( WORD wLang, VER_BLOCK * pVer )
  2539. {
  2540. // Get the DWORD value
  2541. DWORD dwValue = GenerateTransField( wLang, TRUE );
  2542. char buf[9];
  2543. // Put the value in the string value
  2544. wsprintf( &buf[0], "%08lX", dwValue );
  2545. TRACE3("\t\tGenerateTransField: Old: %s\tNew : %s\t dwValue: %lX\n", pVer->szKey, buf, dwValue );
  2546. // Just check if we are in the right place. Should never have problem
  2547. if(strlen(pVer->szKey)==8) {
  2548. // We have to change the header in the image, not just the szKey field
  2549. // Get the pointer to he begin of the field
  2550. WORD wPad = Pad4(pVer->wHead);
  2551. LONG cbDummy =18;
  2552. BYTE far * pHead = pVer->pValue-pVer->wHead-wPad;
  2553. pHead += 6; // Move at the begin of the string
  2554. PutStringW(&pHead, buf, &cbDummy);
  2555. }
  2556. }
  2557. DWORD GenerateTransField(WORD wLang, BOOL bMode)
  2558. {
  2559. // we have to generate a table to connect
  2560. // the language with the correct code page
  2561. WORD wCP = 1200; // Unicode
  2562. if (bMode)
  2563. return MAKELONG( wCP, wLang );
  2564. else return MAKELONG( wLang, wCP );
  2565. }
  2566. LONG Allign( LPLPBYTE lplpBuf, LONG* plBufSize, LONG lSize )
  2567. {
  2568. LONG lRet = 0;
  2569. BYTE bPad =(BYTE)PadPtr(lSize);
  2570. lRet = bPad;
  2571. if (bPad && *plBufSize>=bPad) {
  2572. while(bPad && *plBufSize) {
  2573. **lplpBuf = 0x00;
  2574. *lplpBuf += 1;
  2575. *plBufSize -= 1;
  2576. bPad--;
  2577. }
  2578. }
  2579. return lRet;
  2580. }
  2581. UINT
  2582. ParseEmbeddedFile( LPVOID lpImageBuf, DWORD dwISize, LPVOID lpBuffer, DWORD dwSize )
  2583. {
  2584. // we will return just one item so the iodll will handle this resource as
  2585. // something valid. We will not bother doing anything else. The only thing
  2586. // we are interesed is the raw data in the immage, but if we don't return at
  2587. // least one item IODLL will consider the resource empty.
  2588. BYTE far * lpBuf = (BYTE far *)lpBuffer;
  2589. LONG dwBufSize = dwSize;
  2590. LONG dwOverAllSize = 0;
  2591. TRACE1("ParseEmbeddedFile: dwISize=%ld\n", dwISize);
  2592. dwOverAllSize += PutDWord( &lpBuf, sizeof(RESITEM), &dwBufSize);
  2593. // We have the size and pos in a cursor but we are not interested now
  2594. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  2595. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  2596. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  2597. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  2598. // we don't have checksum and style
  2599. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  2600. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  2601. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  2602. //Put the Flag
  2603. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  2604. // The ID will be just 1
  2605. dwOverAllSize += PutDWord( &lpBuf, 1, &dwBufSize);
  2606. // we don't have the resID, and the Type Id
  2607. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  2608. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  2609. // we don't have the language
  2610. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  2611. // we don't have the codepage or the font name
  2612. dwOverAllSize += PutDWord( &lpBuf, (DWORD)-1, &dwBufSize);
  2613. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  2614. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  2615. dwOverAllSize += PutWord( &lpBuf, (WORD)-1, &dwBufSize);
  2616. dwOverAllSize += PutByte( &lpBuf, (BYTE)-1, &dwBufSize);
  2617. dwOverAllSize += PutByte( &lpBuf, (BYTE)-1, &dwBufSize);
  2618. // Let's put null were we don;t have the strings
  2619. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize);
  2620. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize);
  2621. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize);
  2622. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize);
  2623. dwOverAllSize += PutDWordPtr( &lpBuf, 0, &dwBufSize);
  2624. // we just return. This is enough for IODLL
  2625. return (UINT)(dwOverAllSize);
  2626. }