|
J_E_D_I wrote: Is it possible to read and write to and from very specific locations leving the rest unchanged?
Probably, but I would find it a lot easier to read the file into some sort of data structure, make the necessary changes, and write the data structure back to disk.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi all,
I am transferring to .NET 2003 to .NET 2005 now. I have one application made in Visual C++.NET 2003. It is compiling fine in .NET 2005 but it gives one run time error at ShowDialog() function of OpenFileDialog Class object. Error is
"An unhandled exception of type 'System.Threading.ThreadStateException' occurred in System.Windows.Forms.dll
Additional information: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process."
Can I know what is wrong with this? And how can I solve this problem.
Thanks in advance,
Priyank
|
|
|
|
|
This should be posted on the Managed C++/CLI board.
I'm not sure what threads have to do with using the OpenFileDialog, but the error message is
pretty descriptive - it even states how to fix it.
Which version of ShowDialog() are you using?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
"Ensure that your Main function has STAThreadAttribute marked on it."
Have you tried this?
|
|
|
|
|
Are you switching to the "dark side of the force"?
Steve
|
|
|
|
|
I think Mike's onto something here; the error message is describing exactly what's wrong. See here[^] for more details.
Steve
|
|
|
|
|
I am using Visual Studio 2005, with Visual C++, and have generated a single docuemnt project with mainframe and childview for MFC.
I want to display parts of an image that the program loads from a bitmap file, on a grid pattern as produced by CGrid class in Grid.h and Grid.cpp.
When I use the StretchBlt function, the program asks for a HDC!!!!
I have not found litterature or samples for the use of that device context.
Would you know of a solution?
Thanks for any help....
Here is a possible code section for my function. With it, I can enter a string but not the image. It creates a CDC* but not a HDC. How should I code the HDC?????
void CGrid::FillCell(int r, int c, CString val, COLORREF brushColor, CImage m_Image)
{
CWnd* pWnd = AfxGetMainWnd();
CDC* pDC = pWnd->GetDC();
// pDC->BitBlt(0,0,20,20,pDC,0,0,SRCCOPY);
CBrush* pBrush;
pBrush = new CBrush (brushColor);
pDC->FillRect (mGrid[r][c],pBrush );
delete pBrush;
pDC->SetBkMode (TRANSPARENT);
pDC->SetTextColor (mStringColor);
pDC->DrawText(val,-1,mGrid[r][c],
DT_SINGLELINE |
DT_CENTER |
DT_VCENTER
);
// m_Image.StretchBlt(pDC,mGrid[r][c].TopLeft().x,mGrid[r][c].TopLeft().y,mGrid[r][c].Width(),mGrid[r][c].Height(),mGrid[r][c].TopLeft().x,mGrid[r][c].TopLeft().y,mGrid[r][c].Width(),mGrid[r][c].Height(),SRCCOPY);
// pDC->StretchBlt(mGrid[r][c].TopLeft().x,mGrid[r][c].TopLeft().y,mGrid[r][c].Width(),mGrid[r][c].Height(),m_Image,mGrid[r][c].TopLeft().x,mGrid[r][c].TopLeft().y,mGrid[r][c].Width(),mGrid[r][c].Height(),SRCCOPY);
pWnd->ReleaseDC(pDC);
}
guybour
|
|
|
|
|
Is the destination grid pattern on a window?
If so, then your code should work. Instead of trying to pass "pDC" as the destination DC,
pass "*pDC". This forces the compiler to use the CDC (HDC) cast operator to extract the HDC from
the CDC object. CDC is a C++ wrapper for an HDC.
You may need to get a DC for the window the grid is on, not the main frame window. The main
frame window is covered by a child view window. The view window is the one you want the DC for,
or whichever window you want to draw the image on.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
For starters, if you are trying to draw on on the view, you are getting a DC for the wrong window. Your getting a DC for the main frame window. From within you view class code, just use "this" since it is a pointer to the view/wnd
CDC* pDC=this->GetDC();
// or
CDC* pDC=GetDC();
Next, make sure the drawing code is in or called from the views OnDraw handler since anytime you drag another window over the view it will erase your drawing like an eraser. The OnDraw will get called and if your drawing code is not there to refresh the image, nothing will happen.
Next make sure you have the correct coordinate system for your drawing. The default mapping mode is MM_TEXT (y-axis positive as it goes down) all other mapping modes like MM_HIMETRIC, MM_HIENGLISH, etc... have the y-axis negative as it goes down. MM_ANISOTROPIC and MM_ISOTROPIC allow you to set the y-axis orientation. I've spent many an hour chasing my tail because my y-axis orientation was incorrect.
// The handle is a member of CDC. To access it use the arrow operator
pDC->m_hDC
// Something like
m_Image.StretchBlt(pDC->m_hDC, etc...
I hope that helps
|
|
|
|
|
Hi. I've been quite a while out of C++, wasn't expert before either. But right now, I got a really strange problem with strcpy. Maybe somebody can help? : )
<br />
char cBuffer[256];<br />
char cTemp[260];<br />
<br />
<br />
char ch = cBuffer[0];
strcpy(cTemp, "R");
strcpy(cTemp, &ch);
So what should I do to put ch in cTemp???
Thank you in advance...
|
|
|
|
|
If you just want to copy the first character from cBuffer to cTemp , then just do:
cTemp[0] = cBuffer[0]; If you want to copy the entire string, then:
strcpy(cTemp,cBuffer); From your example, remember that ch is only a single character. There is no space for a terminating '\0' , so the strcpy is terminating on whatever random garbage follows the ch variable in the stack.
Software Zen: delete this;
|
|
|
|
|
This is really weird. Watch this! I will give you the relevant pieces of code where cTemp and cBuffer are involved. This is really strange for me.
<br />
<br />
char cTemp[260];
char cTemp2[260];
char cBuffer[256];
<br />
GetModuleFileName(0, cTemp, 249);<br />
<br />
ReadFile(hFile, cBuffer, sizeof(char)*256, &dwNumRead, NULL);<br />
<br />
strcpy(cTemp2, cBuffer);
strcpy(cTemp, cBuffer);
<br />
HOWEVER!!! If I move the declaration for cTemp2 straight before the strcpy, it works!!! Like this:
<br />
char cTemp2[260];
strcpy(cTemp2, cBuffer);
sTemp = cTemp2;<br />
Why does it work !?!?!?!?!? What does anything have to do with where I declare the variable !??!!?
I'll give you the full code, maybe there's something there I missed. There are some things here which you won't understand, but try not to get stuck in my local program logic. ASDANSIString is a class I made to work easier with strings. It's a wrapper over a char*, quite similar to the String class in .Net, it has lots of parsing methods incorporated in it.
<br />
<br />
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)<br />
{<br />
ASDANSIString sTemp;
HANDLE hFile;
MSG msgPump;
DWORD dwNumRead;
long lCounter;<br />
char cTemp[260];
<br />
char cBuffer[256];
<br />
bReady = false;
lTimerID = SetTimer(0, 0, 1000, (TIMERPROC)TimerProc);
<br />
GetModuleFileName(0, cTemp, 249);
sTemp = cTemp;
sTemp = sTemp.SubStringA(0, sTemp.IndexOfRev("\\", 0));
sTemp += "\\Window Name.txt";
<br />
hFile = CreateFile(sTemp, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); <br />
ReadFile(hFile, cBuffer, sizeof(char)*256, &dwNumRead, NULL);<br />
CloseHandle(hFile);<br />
<br />
char cTemp2[260];
strcpy(cTemp2, cBuffer);<br />
sTemp = cTemp2;<br />
<br />
MessageBox(0, sTemp, "Test", 0);<br />
<br />
while (!bReady && GetMessage(&msgPump, NULL, 0, 0))
{<br />
TranslateMessage(&msgPump);<br />
DispatchMessage(&msgPump);<br />
}<br />
<br />
return 0;<br />
}<br />
<br />
|
|
|
|
|
Remember that ReadFile() is not a CRT function - it makes no guarantees about nul-terminating the data it reads. Try this, it will probably work:
char cBuffer[256] = { 0 };
|
|
|
|
|
Indeed you are right. This solved all the strange problems I've been seeing, even though I still can't explain why (in the above post) declaring a char just before the strcpy did not crash. Well, too much to do today to busy myself with finding that out : (... guess it'll remain to be checked out in the future : D. Thank you very much. You're in the "Thanks To..." list : D. You'll soon see where (in what software... but don't worry, it's free, you made a good deed).
EDIT:
I've been thinking about this and maybe it's perhaps when I declare the char[] before reading from that file, the char is initialized by C++ while when declaring it after reading from the file it is not? Hmmmmmm. Doesn't make much sense. Hrmph... whatever...
|
|
|
|
|
Axonn Echysttas wrote: ReadFile(hFile, cBuffer, sizeof(char)*256, &dwNumRead, NULL);
Try this:
ReadFile(hFile, cBuffer, sizeof(char)*256, &dwNumRead, NULL);
cBuffer[dwNumRead] = '\0';
strcpy(cTemp2,cBuffer); As mentioned elsewhere, ReadFile simply reads bytes from a file. It does not guarantee that a terminator is placed in the destination. The line I've added places a '\0' terminator after the data read, so that it's safe later on to perform the strcpy .
Software Zen: delete this;
|
|
|
|
|
While a char* is often called a "string" in C, they are not the same thing. A "string" is a specially-formatted array of chars. Taking the address of one single char doesn't make it a string.
|
|
|
|
|
Hello,
I want to map a particular partition into memory using CreateFileMappingA.
<br />
_dev = CreateFileA(<br />
"\\\\.\\Z:",<br />
GENERIC_ALL,<br />
0,<br />
NULL,<br />
OPEN_EXISTING,<br />
FILE_ATTRIBUTE_NORMAL,<br />
NULL<br />
);<br />
<br />
_devMap = CreateFileMappingA(<br />
_dev,<br />
NULL,<br />
PAGE_READONLY,<br />
0,<br />
0,<br />
NULL<br />
);<br />
<br />
Opening the driver with CreateFileA works fine,
but CreateFileMappingA returns NULL.
I get the error code 87 which is the following:
ERROR_INVALID_PARAMETER
87 The parameter is incorrect.
Since it's a 64bit application there shouldn't be any problems with
mapping large files into memory.
Thanks in advance.
|
|
|
|
|
I believe CreateFileMapping requires an actual file.
|
|
|
|
|
You are passing CreateFileMapping() a handle to something that is not a file, thus the invalid parameter message.
|
|
|
|
|
<emp>
<name>biswa</name>
<adress>marathahli</adress>
<id>9888</id>
</emp>
coding in vc++ but looks like above
biswajit nayak
|
|
|
|
|
Will you stop spamming the forums ?
If you want a decent answer, you first have to provide a decent question. I don't see any question at all in your message. It is just a piece of XML and one sentence.
And, BTW, somebody already gave you a correct answer if you want to do XML with C++ in one of your (too many) previous post.
|
|
|
|
|
Some people never learn. I just hope he doesn't get hired to implement an air traffic control system.
|
|
|
|
|
|
elephants
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi,
I want to do magnification on my window. I set the window extension to doubled. When I draw one line, actually it draws a 2-pixel line on the window. If that line is around the border of the window, it is possible only 1-pixel shown up. Now, if I size the window, windows doesn't invalidate the other pixel of that line which it thinks it was already shown. In other words, windows only invalidate the area by logical coordinate, it doesn't know there are some pixels in that coordinate are missed and need to invalidate again. How do I work it around? Thanks a lot.
|
|
|
|
|