Menu menubar = getShell().getMenuBar();
private int InsertMenus(int hmenuShared, int lpMenuWidths) {	// locate menu bar	if (menubar == null || menubar.isDisposed()) {		COM.MoveMemory(lpMenuWidths, new int[] {0}, 4);		return COM.S_OK;	}	int hMenu = menubar.handle;	// Create a holder for menu information.  This will be passed down to	// the OS and the OS will fill in the requested information for each menu.	MENUITEMINFO lpmii = new MENUITEMINFO();	int hHeap = OS.GetProcessHeap();	int cch = 128;	int byteCount = cch * TCHAR.sizeof;	int pszText = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount);	lpmii.cbSize = MENUITEMINFO.sizeof;	lpmii.fMask = OS.MIIM_STATE | OS.MIIM_ID | OS.MIIM_TYPE | OS.MIIM_SUBMENU | OS.MIIM_DATA;	lpmii.dwTypeData = pszText;	lpmii.cch = cch;	// Loop over all "File-like" menus in the menubar and get information about the	// item from the OS.	int fileMenuCount = 0;	int newindex = 0;	if (this.fileMenuItems != null) {		for (int i = 0; i < this.fileMenuItems.length; i++) {			MenuItem item = this.fileMenuItems[i];			if (item != null) {				int index = item.getParent().indexOf(item);				lpmii.cch = cch;  // lpmii.cch gets updated by GetMenuItemInfo to indicate the 				                  // exact number of characters in name.  Reset it to our max size 				                  // before each call.				if (OS.GetMenuItemInfo(hMenu, index, true, lpmii)) {					if (OS.InsertMenuItem(hmenuShared, newindex, true, lpmii)) {						// keep track of the number of items						fileMenuCount++;						newindex++;					}				}			}		}	}	// copy the menu item count information to the pointer	COM.MoveMemory(lpMenuWidths, new int[] {fileMenuCount}, 4);	// Loop over all "Container-like" menus in the menubar and get information about the	// item from the OS.	int containerMenuCount = 0;	if (this.containerMenuItems != null) {		for (int i = 0; i < this.containerMenuItems.length; i++) {			MenuItem item = this.containerMenuItems[i];			if (item != null) {				int index = item.getParent().indexOf(item);				lpmii.cch = cch; // lpmii.cch gets updated by GetMenuItemInfo to indicate the 				                           // exact nuber of characters in name.  Reset it to a large number 				                           // before each call.				if (OS.GetMenuItemInfo(hMenu, index, true, lpmii)) {					if (OS.InsertMenuItem(hmenuShared, newindex, true, lpmii)) {						// keep track of the number of items						containerMenuCount++;						newindex++;					}				}			}		}	}		// copy the menu item count information to the pointer	COM.MoveMemory(lpMenuWidths + 8, new int[] {containerMenuCount}, 4);	// Loop over all "Window-like" menus in the menubar and get information about the	// item from the OS.	int windowMenuCount = 0;	if (this.windowMenuItems != null) {		for (int i = 0; i < this.windowMenuItems.length; i++) {			MenuItem item = this.windowMenuItems[i];			if (item != null) {				int index = item.getParent().indexOf(item);				lpmii.cch = cch; // lpmii.cch gets updated by GetMenuItemInfo to indicate the 				                           // exact nuber of characters in name.  Reset it to a large number 				                           // before each call.				if (OS.GetMenuItemInfo(hMenu, index, true, lpmii)) {					if (OS.InsertMenuItem(hmenuShared, newindex, true, lpmii)) {						// keep track of the number of items						windowMenuCount++;						newindex++;					}				}			}		}	}		// copy the menu item count information to the pointer	COM.MoveMemory(lpMenuWidths + 16, new int[] {windowMenuCount}, 4);			// free resources used in querying the OS	if (pszText != 0)		OS.HeapFree(hHeap, 0, pszText);	return COM.S_OK;}