|
Here you go:
<pre> if (add_uevent_var(env,
"MODALIAS=usb:"
"v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X",
le16_to_cpu(copy_dev->descriptor.idVendor),
le16_to_cpu(copy_dev->descriptor.idProduct),
le16_to_cpu(copy_dev->descriptor.bcdDevice),
copy_dev->descriptor.bDeviceClass,
copy_dev->descriptor.bDeviceSubClass,
copy_dev->descriptor.bDeviceProtocol,
alt->desc.bInterfaceClass,
alt->desc.bInterfaceSubClass,
alt->desc.bInterfaceProtocol))
return -ENOMEM;
modified 18-Jul-13 9:11am.
|
|
|
|
|
Hi,
I'm using wofstream to write text to a file
my problem is that, with any level of optimization, neither write() or << allows me to write a wstring or c string in the form of (WCHAR*).
example
WCHAR* str = new WCHAR[MAX_PATH];
wcscpy(str, L"walk");
myfile.write(str, wcslen(str));
No string written to file
wstring str2 = L"walk";
myfile << str2;
No string written to file
I am able to to do
myfile << "String";
how do I fix?
|
|
|
|
|
Unfortunately you don't. The wstream types take wide characters in but write them out as normal ASCII. You should use the old C-style fwrite or the newer WriteFile functions which allow you to specify the output character size.
Use the best guess
|
|
|
|
|
so wofstream can't be optimized? it all works well without optimization
|
|
|
|
|
doug25 wrote: so wofstream can't be optimized? it all works well without optimization Sorry, I don't understand what you are saying here. As far as Irecall from all the tests I have run, you cannot write wide characters via a wstream. I would be interested to see the code you have that does work. In the meantime I will retry my own tests.
Use the best guess
|
|
|
|
|
sorry, I've discovered what was happening, it isn't a problem with wstring optimazation. I was converting the file to another format the functions i'm using behave differently with optimization.
The problem is nothing to do with vectors or wstrings. it's a directx set of functions i'm using that fail when optimazation is turned on. It was difficult to determine tat this was where the program was failing.
modified 17-Jul-13 12:17pm.
|
|
|
|
|
doug25 wrote: the functions i'm using behave differently with optimization. I find that very difficult to believe. Much more likely is that you have a bug somewhere that only shows when you have optimization turned on.
Use the best guess
|
|
|
|
|
well, it could be a mistake I've made but I've managed to find exactly where the error occurs by using #pragma optimize("g", off)
and
#pragma optimize("g", on)
it's one function, I can't see any mistakes
#pragma optimize("g", off)
void AddDataObject(ID3DXFileSaveObject* xFileSave, ID3DXFileData* child, ID3DXFileSaveData* xSaveData)
{
SIZE_T nChildren = 0;
child->GetChildren(&nChildren);
GUID templateid, id;
child->GetType(&templateid);
child->GetId(&id);
char name[MAX_PATH];
SIZE_T sz;
child->GetName(name, &sz);
SIZE_T dataSize;
void* data = NULL;
child->Lock(&dataSize, (LPCVOID*)&data);
if(xSaveData)
{
xSaveData->AddDataObject(templateid, name, (const GUID*)&id, dataSize, data, &xSaveData);
}
else
{
xFileSave->AddDataObject(templateid, name, (const GUID*)&id, dataSize, data, &xSaveData);
}
child->Unlock();
for(int i=0; i<nChildren; i++)
{
ID3DXFileData* ch = NULL;
if(SUCCEEDED(child->GetChild(i, &ch)))
{
AddDataObject(xFileSave, ch, xSaveData);
}
}
}
#pragma optimize("g", on)
|
|
|
|
|
What problem and where does it occur?
Use the best guess
|
|
|
|
|
the problem is some strings are not loaded, or at least are not written to the new file. e.g. each line in the output file that should contain "Frame frame_name {" (works without opt.) reads "Frame {".
I will try freeing the memory of child data objects although I have assumed they get released when the top level data object get released and I will try what Jochan suggested.
There is very little documentation on how to use these functions.
I won't be able to reply for a while if I do fix the problem but cheers.
|
|
|
|
|
doug25 wrote: the problem is some strings are not loaded, or at least are not written to the new file. e.g. each line in the output file that should contain "Frame frame_name {" (works without opt.) reads "Frame {". Now I'm totally lost; the code you posted does not seem to have anything at all to do with these comments. It may be better to close off this thread and start a new question when you are ready to proceed.
Use the best guess
|
|
|
|
|
I haven't explained it very well. Basically, I've written a program that writes a .x file using wofstream. But the file doesn't look very pretty so I'm using the directx code I posted to convert it to a better format, so I can also save it as binary or compressed as well as structured text. Basically saves me having to rewrite the program.
I'll close the thread.
|
|
|
|
|
|
You can just stop posting, or edit your original question and add "[closed]" or "[solved]" to the title, and a comment to the effect that you have closed it.
Use the best guess
|
|
|
|
|
That is a recursive function. You may generate assembler output to see the differences between the optimized and unoptimized code.
You should also check for success on all functions that may fail. At least the AddDataObject() return values should be checked and returned upon errors to leave the recursion if something wrent wrong.
|
|
|
|
|
|
Using VS2008 Prof. on Windows8, a Win32 ListView control in Report mode doesn't display any icons at the start of each row. It shows data which I can sort, but no icons.
I'm assuming its some bit or attribute not set somewhere so have to show all the relevant code for someone to see what I'm missing. The list (header)setup code is here (followed by the row insertion code taken out of its loop and then my test code). All error handling removed. I've compared this to an ATL/WTL program that shows the icons and I can't see any difference.
The image list is initialised by the CDeviceImageList constructor which uses the below code to initialize the list:
class CDeviceImageList
{
private:
SP_CLASSIMAGELIST_DATA m_spImageData; public:
CDeviceImageList()
{
RtlZeroMemory(&m_spImageData, sizeof(SP_CLASSIMAGELIST_DATA));
m_spImageData.cbSize = sizeof(SP_CLASSIMAGELIST_DATA);
BOOL b = SetupDiGetClassImageList(&m_spImageData);
if(FALSE == b)
{
assert(!"Failed to aquire class image list");
}
}
operator HIMAGELIST() const throw()
{
return m_spImageData.ImageList;
}
...
ListView setup before the data ...
LVITEM lvItem;
SecureZeroMemory(&lvItem, sizeof(LVITEM));
LVCOLUMN lvCol;
SecureZeroMemory(&lvCol, sizeof(LVCOLUMN));
HWND hList=GetDlgItem(hwnd,IDC_LIST1);
lvCol.pszText=L"Port"; lvCol.mask=LVCF_TEXT;
lvCol.cx=60; lvCol.mask |= LVCF_WIDTH;
lvCol.iSubItem = 0; lvCol.mask |= LVCF_SUBITEM;
lvCol.fmt = HDF_SORTUP; lvCol.fmt |= LVCFMT_LEFT; lvCol.mask |= LVCF_FMT;
int nCol = 0;
nCol = ListView_InsertColumn(hList, lvCol.iSubItem, &lvCol);
lvCol.iSubItem = 1; lvCol.pszText=L"Device"; lvCol.cx=220; nCol = ListView_InsertColumn(hList, lvCol.iSubItem, &lvCol);
lvCol.iSubItem = 2; lvCol.pszText=L"Manufacturer"; lvCol.cx=100; nCol = ListView_InsertColumn(hList, lvCol.iSubItem, &lvCol);
CDeviceImageList cImageList;
HIMAGELIST hImageList = cImageList;
HIMAGELIST hRet = ListView_SetImageList(hList, hImageList, LVSIL_SMALL,);
ListView_SetExtendedListViewStyle(hList, LVS_EX_INFOTIP | LVS_SHOWSELALWAYS);
At this point I can get the image list back from the ListView
The relevant row insertion code, after which I can get the icons, is below but the ListView doesn't display them...
LVITEM lvItem;
SecureZeroMemory(&lvItem, sizeof(LVITEM));
lvItem.mask=LVIF_TEXT; lvItem.cchTextMax = 0;
lvItem.iItem=n; lvItem.iSubItem=0; lvItem.pszText=m_pData[n]->szName;
lvItem.iImage = ImageIndex;
lvItem.mask |= LVIF_IMAGE;
lvItem.lParam=(LPARAM)m_pData[n];
lvItem.mask |= LVIF_PARAM;
HWND hList=GetDlgItem(hwnd,IDC_LIST1);
int nItemIndex = ListView_InsertItem(hList, &lvItem);
lvItem.lParam=0;
lvItem.mask &= ~LVIF_PARAM;
lvItem.iImage = 0;
lvItem.mask &= ~LVIF_IMAGE;
lvItem.iSubItem=1;
lvItem.pszText=(LPTSTR)(LPCTSTR)szData[n][1];
ListView_SetItem(hList, &lvItem);
lvItem.iSubItem=2;
lvItem.pszText=(LPTSTR)(LPCTSTR)szData[n][2];
ListView_SetItem(hList, &lvItem);
After each loop above I can use the following three lines to get the icons (and a few more to display them as proof). But the ListView still refuses to show them...
HWND hList=GetDlgItem(hwnd,IDC_LIST1);
HIMAGELIST hGotList = ListView_GetImageList(hList, LVSIL_SMALL);
HICON hIcon = ImageList_GetIcon(hGotList, ImageIndex, ILD_NORMAL);
modified 17-Jul-13 5:07am.
|
|
|
|
|
Hi,
How are you creating your image list? Are these 32 bit icons?
About Image Lists[^]
Best Wishes,
-David Delaune
|
|
|
|
|
David,
I've now added the code showing the creation of the image list to my question as you're not the only one to ask how it's created or initialized. Basically my CDeviceImageList constructor uses a call to SetupDiGetClassImageList[^].
At the end of my list setup and data initialization I can use the last three lines of code shown to basically: GetDialog, GetListView, and GetIcon followed by a call to
SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); to display in the top-left corner of the dialog the very icon I expect to see in the ListView. which would seem to prove the ImageList in the ListView has the icons.
Are they 32 bit? Not to my knowledge.
I've read the stuff on ImageLists, ListViews etc. until I almost know it by heart.
|
|
|
|
|
CDeviceImageList cImageList;
HIMAGELIST hImageList = cImageList;
HIMAGELIST hRet = ListView_SetImageList(hList, hImageList, LVSIL_SMALL,);
I note that you are using the CDeviceImageList class from this Article[^], in which case you should post your question in the forum at the end of the article to dicuss with the author. Although it looks to me that you have not initialised the object with any icons.
Use the best guess
|
|
|
|
|
Richard,
I've asked the Author of that CDeviceImageList class article you refer to (me) and he's sure the list is initialized - though he cold of course be wrong. I've now added the code from the constructor of this class to the question to show how its initialized.
Tp prove the ListView ImageList is initialized, After setting up the list I can use the three lines show at the end of my question, which are basically,
GetDialog, GetListView, GetIcon , followed by
SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); to display the exactly the icon I'm looking for in the top-left corner of the dialog box.
Which seems to prove the initialization.
|
|
|
|
|
Then that suggests that you are not usiing the correct values when you add an item to the ListView. I would suggest you step through with your debugger to see which icon index is being used when you add an item to the control.
Use the best guess
|
|
|
|
|
Richard,
Stepped through it repeatedly, also side by side comparing it with working ATL/WTL example. I've just typed and run the below test at the end of the loop that fills rows with data where n is the loop variable. I get the LVITEM.iImage which is the index for the row, get a completely new ImageList from the ListView and get the icon from that ImageList successfully and can display it in the dialog top-left corner for any n .
LVITEM lvItemP2;
SecureZeroMemory(&lvItemP2, sizeof(LVITEM));
lvItemP2.mask = LVIF_IMAGE;
lvItemP2.iItem = n;
BOOL bGotItem2 = ListView_GetItem(hList, &lvItemP2);
HIMAGELIST hNewImageList = ListView_GetImageList(hList, LVSIL_SMALL);
if(NULL == hNewImageList)
{
DWORD dwErr = GetLastError();
std::wstring szErr = CWin32ErrToWString()(dwErr);
assert(!"Failed to get image list during test");
}
HICON hIconP2 = ImageList_GetIcon(hNewImageList, lvItemP2.iImage, ILD_NORMAL);
if(NULL == hIconP2)
{
DWORD dwErr = GetLastError();
std::wstring szErr = CWin32ErrToWString()(dwErr);
assert(!"Failed to get icon from image list during test");
}
SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIconP2);
|
|
|
|
|
All well and good, but it does not really address your problem, which is about setting the imagelist and image index correctly in your list view items.
Use the best guess
|
|
|
|
|
I'd say that getting the imagelist from the listview and getting the index into that list from each set of row data and using that index into the imagelist to come up with the expected icon shows I'm setting the imagelist and index correctly and the reason for non-display must be something else.
Stepping through each row item is set with image-index 0x1A, and this is also the value extracted from each row item after setting it.
The imagelist when obtained is of size 0x4A images as is the imagelist extracted from the listview later.
|
|
|
|
|