|
GetDlgItem() returns a CWnd* so the (CWnd*) cast does nothing.
MFC keeps per-thread maps of some objects, for example that's how it associates a CWnd and an HWND . If an MFC function creates a temp object - one that's not kept in a map - then the temp object may be deleted at any time after your function returns. That's why the docs say don't store the pointer. If you need a longer-lived object, use CWnd::FromHandle() or an equivalent.
|
|
|
|
|
I'm trying to open a dialog box to the user and than take the filename they select and pass it too a DirectX api call which gets details about that file. I've been messing around with this for a few nights and I've got absolutely nowhere. I've read a lot about character encoding and although there are still a few blanks in my understanding I have a fairly good grasp of it. I'd imagine what I'm trying to do is simple enough and I'm running into pitfalls which are common place but no matter what I attempt to do I can't seem to get around these errors. Anyway here's my code, please take a look and if you could shed some light you'd really be doing me a huge favour.
I was given this in an earlier forum post, I really don't understand what it does, but it fixed an eariler problem I had so its in there for now.
#ifdef _UNICODE<br />
typedef wstring tstring;<br />
#else<br />
typedef string tstring;<br />
#endif
This is my function to display a file select dialog box and returns a tstring of the full path.
tstring openFile()<br />
{<br />
OPENFILENAME ofn;
TCHAR szFile[_MAX_PATH];
HANDLE test;<br />
<br />
ZeroMemory(&ofn, sizeof(ofn));<br />
ofn.lStructSize = sizeof(ofn);<br />
ofn.hwndOwner = mainLoop.hWnd;<br />
ofn.lpstrFile = szFile;<br />
ofn.lpstrFile[0] = '\0';<br />
ofn.nMaxFile = sizeof(szFile);<br />
ofn.lpstrFilter = _T("All\0*.*\0Text\0*.TXT\0");<br />
ofn.nFilterIndex = 1;<br />
ofn.lpstrFileTitle = NULL;<br />
ofn.nMaxFileTitle = 0;<br />
ofn.lpstrInitialDir = NULL;<br />
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;<br />
<br />
<br />
if (GetOpenFileName(&ofn)==TRUE) <br />
test = CreateFile(ofn.lpstrFile, GENERIC_READ,<br />
0, (LPSECURITY_ATTRIBUTES) NULL,<br />
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,<br />
(HANDLE) NULL);<br />
<br />
<br />
<br />
tstring temp (ofn.lpstrFile);<br />
<br />
return temp;<br />
<br />
}
When I call this the contents of Info remain null, so I'm guessing what's happening here is the encoding of fileName is incorrect for this function.
fileName = openFile();<br />
<br />
D3DXGetImageInfoFromFile(fileName.c_str(), &Info);
If I call it with the value hardcoded like so:
D3DXGetImageInfoFromFile(_T("F:\\Pictures\\ShannonTrip2006-PrintRun\\ShannonTrip2006 326.jpg"))
it works, it also works if I do the following:
fileName = _T("F:\\Pictures\\ShannonTrip2006-PrintRun\\ShannonTrip2006 326.jpg");<br />
<br />
D3DXGetImageInfoFromFile(fileName.c_str(), &Info);
The memory of fileName in this call looks exactly the same as the memory used when I'm getting the value from openFile() yet one works and the other doesn't. Not sure where I can look after this, any help is greatly appreciated.
|
|
|
|
|
You have problem with return value of fileName.c_str() ?
|
|
|
|
|
Yes when I try to pass fileName.c_str() into the api call when I've gotten its value from the windows file dialog it returns an error, when I attempt it after setting its value with a literal wrapped in _T it works. The memory of the two looks the exact same so I can't tell why one is failing and the other isn't.
|
|
|
|
|
I run your code and fileName.c_str() return file(full with path) but what error?
|
|
|
|
|
The api call returns 0x88760b59 which is D3DERR_INVALIDCALL, which means one of the parameters wasn't valid. The open file part isn't a problem that's getting the file and path out fine, its just when I pass what's being returned by that into a Unicode method I get a invalid call error.
|
|
|
|
|
Hi,
has anyone a idea how to find out the specific device_id for one of my installed soundcards?!
Playing via WAVE_MAPPER is no problem, but i need play on two different sound devices at the same time....
Please help me (maybe with a codesnippet).
Regards,
Alexander
P.S.: I am calling all available device via WaveOutDevsGetNum and its capabilities via WaveOutDevsCaps...
-- modified at 18:04 Friday 6th October, 2006
|
|
|
|
|
Hi everyone
I am running the following piece of code on Windows 2000 and XP (except the code below has been simplified with error checking removed).
This code spawns a child process, which writes its output to a logfile called child.log.
The problem I am having is: if the child process is a command or batch file (example below), then child.log captures output of commands such as "dir",
however, for any processes that are launched from the batch script, such as perl.exe, all the output is lost. I don't know where the
output is going or why. I suspect I have done something wrong with handle inheritance somewhere.. any ideas??
I don't get the same problem if the child process is some other shell interpreter, such as bash.exe.
.........................
SECURITY_ATTRIBUTES secAttr;
secAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
secAttr.bInheritHandle = TRUE;
secAttr.lpSecurityDescriptor = NULL;
STARTUPINFO startupInfo;
::ZeroMemory((void*) &startupInfo, sizeof(STARTUPINFO));
startupInfo.cb = sizeof(STARTUPINFO);
startupInfo.dwFlags = STARTF_USESTDHANDLES;
PROCESS_INFORMATION processInfo;
startupInfo.hStdOutput = CreateFile(
"child.log",
GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ,
&secAttr,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_SEQUENTIAL_SCAN,
NULL);
startupInfo.hStdError = startupInfo.hStdOutput;
CreateProcess(
NULL,
"test.bat",
NULL,
NULL,
TRUE,
DETACHED_PROCESS,
NULL,
NULL,
&startupInfo,
&processInfo);
// Close handle because parent process has no further need for it:
CloseHandle(startupInfo.hStdOutput);
..................
Example of test.bat:
----------------------------
rem test.bat
rem dir command gives output in child.log, but "perl -v" does not !!
dir
perl -v
exit 0
cheers,
Neil
|
|
|
|
|
Hello,
I downloaded the Microsoft ISAPI esample AuthFilt. I followed all the instructions built it and tried it. When I used the user name and password in the "C:\inetsrv\userdb.txt" to login, the login page always showed up.
Could somebody please help me and tell why that happened?
Thanks and best regards
William
|
|
|
|
|
I have a number of images(100 or more) that need to be processed and displayed using MFC. The processing is very cpu intensive. I process the images in the main dialog, and display the result images in a child dialog, by calling the the Invalidate() and UpdateWindow() pair to redraw the child dialog after the processing of each image. And now the program is single threaded.
But the display freezes after some frames has been displayed correctly.
In the OnPaint() of the child dialog, I call this function:
void CDisplayDlg::ShowBitmap(CPaintDC *pdc, CBitmap* pBitmap)
{
BITMAP bm;
pBitmap->GetBitmap(&bm);
CDC dcMem;
dcMem.CreateCompatibleDC(pdc);
CBitmap* pOldBitmap=(CBitmap*) dcMem.SelectObject(pBitmap);
pdc->BitBlt(0,0,bm.bmWidth,bm.bmHeight,&dcMem,0,0,SRCCOPY);
dcMem.SelectObject( pOldBitmap);
DeleteDC(dcMem);
}
And this is the OnPaint():
void CDisplayDlg::OnPaint()
{
CPaintDC dc(this);
CFADlg *pWnd = (CFADlg *)GetParent();
if(pWnd)
{
ShowBitmap(&dc, &pWnd->m_bmpBitmap);
}
int m=ReleaseDC(&dc);
TRACE("m: %d\n", m);
}
After processing of all the images, the child dialog displays the last processed image. I have also tried using GDI+ to implement the showbitmap, but it has the same problem.
What should I do with this? At first I thought that was because I used up all the DC resources. Or maybe I need to use multithread it?
I will really appreciate any help from you. Thanks a lot!
-- modified at 14:21 Friday 6th October, 2006
|
|
|
|
|
Bighand2000 wrote: The processing is very cpu intensive.
Bighand2000 wrote: the display freezes
Bighand2000 wrote: maybe I need to use multithread it?
yes
led mike
|
|
|
|
|
Thanks for your suggestion.
|
|
|
|
|
Did you use of thread or timer for read files because I think you read files and also you process files,right?
--------
And a question did you see PF usage on TaskManager when you run your program if you use of a wrong code then
PF usage will increase I had this problem for example It was 162MB but after run my program It was 300MB
|
|
|
|
|
WhiteSky wrote: Did you use of thread or timer for read files because I think you read files and also you process files,right?
--------
I do not use any thread or timer for reading files. I just read in the image one by one, process it, display it, then write it out(this does not change anything with the display freeze problem). Generally, about 2 or 3 images can be processed each second.
-- modified at 15:29 Friday 6th October, 2006
|
|
|
|
|
about 2 or 3 images can be processed each second if you have files with Dimensions 2331 x 3240 how long to read them?
|
|
|
|
|
My file is 720x480, grayscale uncompressed image( .pgm), size is about 330kB each. So it does not take much time to read.
I turned off the process step, just read in and display the images, but the display still freezes after about 100 frames(the freezing happens after about 20-50 fames when the process step is there).
|
|
|
|
|
And after freeze what happen for your program it returns to normal state or no and one thing
did you trace your program line to line (I know Its hard) if yes what happen in this case its working or no
|
|
|
|
|
The calculation looks fine, since all the processed frames are written out as expected. After all the frames are done, the display is refreshed to show the last processed image.
So of all the steps for each frame: read in, process, display, write out, only display has problem: it freezes after some processed frames(maybe 20, maybe 50) are displayed.
|
|
|
|
|
And what happen for PF usage on TaskManager? it increase or no
|
|
|
|
|
The PF usage is normal when the display freeze, no difference compared to when the display is ok.
I am thinking of DC resource leak. I wrote another simple program that just read in and display the images one by one, the display freeze after some images are read.
|
|
|
|
|
If you have this problem in new program how to read images?
|
|
|
|
|
In the programs mentioned in my previous posts under this topic, I use a CBitmap member variable to contain the images read in or processed. And I use the OnPaint of the display dialog(a separate dialog window) to display it. Every time a new image was read in or processed, the CBitmap variable was updated and Invalidate() and Redrawindow() were called to refresh the display.
Today, I discarded Invalidate() and RedrawWindow(), instead I used CClientDC and DrawImage() directly to the display dialog, and it seems the problem has been solved. But I can not move the display window and it seems the thread was too busy to response.
This is a snippet of the code:
CClientDC dc(&m_dlgDisplay);
Graphics graphics(dc.m_hDC);
for(int i =0; i<700; i++)
{
strMiddle.Format(_T("%04d"), i);
fn=strPrefix+strMiddle+_T(".jpg");
if(m_image)
delete m_image;
m_image=Image::FromFile(fn);
graphics.DrawImage(m_image, 0, 0);
}
-- modified at 21:48 Saturday 21st October, 2006
|
|
|
|
|
Your code doesnt problem and thats right that you disable Sleep and also delete image if it was exist but about for wheres this loop is it possible for you to use of a thread or is it possible to use a timer instead use of for in timer you use of this code but with a difference you need to check if i=700 then killtimer and for this problem I think you have two problems first busy and second(I think)Mem usage of your program that if you move external windows on your program then if you see Mem usage of your program what happens? I research about this problem previous because I had been this problem and I know your problem you can also useof CImage class for read files and for darw their use of BitBlt that is a member of this class
I hope it helpfuls for you but if you have any problem you can aks.
|
|
|
|
|
I've got about 200 structures which have to be byte aligned for the communication with the target over the serial port.
Currently I'm using #pragma pack and memcpy because that was the easiest solution and works well on the x86.
But the downside is that this results in misalignment and is not portable.
Writing a reader and writer for each structure would result in a lot of code and I would like port it to an ARM microcontroller where resources are limited. I also would like to avoid to use C++ and stick with C for this.
The structures contain only 8 and 16-bit members, so each members size could be represented with 1-bit.
|
|
|
|
|
Andre Buenger wrote: But the downside is that this results in misalignment
Where, when?
Andre Buenger wrote: I would like port it to an ARM microcontroller
Byte alignment restrictions are processor dependent. Compilers pad based on the target processors restrictions. Byte alignment is not portable by definition. However reading/writing the same structure to/from the same processor should not be an issue.
led mike
|
|
|
|