|
I have this problem. A class I am using has using namespace std within a included header. My problem is that this class has parameters named "list" (of type string) and "vector" (float[3]) which will cause a class template error.
Rather than rename the parameters or remove 'using namespace', is there something else that I can do?
Thanks
---
|
|
|
|
|
Rather than rename the parameters or remove 'using namespace', is there something else that I can do?
No, but removing using namespace should cause no problems: simply delete this line (which is a big no-no in header files) and prefix every name belonging in the standard library with std:: . It's as simple as this.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Does anyone know of commercially available library that could parse incoming multi-mime HTTP posts?
Thanks,
John
|
|
|
|
|
here is a code snippet that may help you (or not...)
static char cpBoundaryTag[] = "boundary=";
static char cpContentDispTag[] = "Content-Disposition: ";
static char cpContentTypeTag[] = "Content-Type: ";
static char cpNameTag[] = "name=";
static char cpFileNameTag[] = "filename=";
BOOL WorkerThreadObj::ReadMultiPartMessage()
{
m_bIsMultiPartRequest = TRUE;
char caBoundary[256];
char *cpBoundary = strstr(m_pECB->lpszContentType,cpBoundaryTag);
if (cpBoundary)
{
cpBoundary += strlen(cpBoundaryTag);
while (*cpBoundary == ' ')
cpBoundary++;
strncpy(caBoundary,cpBoundary,255);
caBoundary[255] = 0;
cpBoundary = strchr(caBoundary,' ');
if (cpBoundary)
*cpBoundary = 0;
}
else
{
EraseContent();
StartContent();
WriteTitle();
WriteContent("Multipart Boundary String Not Found! ");
EndContent();
return FALSE;
}
BOOL bDeleteReadBuffer = FALSE;
char *cpReadBuffer = m_cpInputBuffer;
int iReqLength = m_pECB->cbTotalBytes;
if (iReqLength >= m_pLightningServer->m_iInputBufferSize)
{
bDeleteReadBuffer = TRUE;
cpReadBuffer = new char[iReqLength+1];
if (!cpReadBuffer)
{
EraseContent();
StartContent();
WriteTitle();
char caBuf[128];
sprintf(caBuf,"Unable To Allocate Memory To Read All %d Bytes of Request!",iReqLength);
WriteContent(caBuf);
EndContent();
return FALSE;
}
}
memcpy(cpReadBuffer,(LPCTSTR)m_pECB->lpbData,m_pECB->cbAvailable);
*(cpReadBuffer + m_pECB->cbAvailable) = 0;
if (m_pECB->cbAvailable < m_pECB->cbTotalBytes)
{
LPSTR cpTarget = cpReadBuffer + m_pECB->cbAvailable;
DWORD cbRemaining = m_pECB->cbTotalBytes - m_pECB->cbAvailable;
DWORD cbRead;
while (cbRemaining > 0)
{
cbRead = cbRemaining;
if (!m_pECB->ReadClient(m_pECB->ConnID,(LPVOID)cpTarget,&cbRead))
{
EraseContent();
StartContent();
WriteTitle();
char caBuf[128];
sprintf(caBuf,"Unable To Read All %d Bytes of Request!Only %d Bytes Were Able To Be Read!",
m_pECB->cbTotalBytes, m_pECB->cbTotalBytes - cbRemaining);
WriteContent(caBuf);
EndContent();
if (bDeleteReadBuffer)
delete [] cpReadBuffer;
return FALSE;
}
if (cbRead == 0)
break;
cpTarget += cbRead;
cbRemaining -= cbRead;
}
}
*(cpReadBuffer + m_pECB->cbTotalBytes) = 0;
// now, find all boundaries and split up contents
MultiPartParam *pParam = NULL;
char *cpDataStartMarker = NULL;
int iBoundaryLen = strlen(caBoundary);
cpBoundary = cpReadBuffer;
char *cpEnd = cpReadBuffer + m_pECB->cbTotalBytes;
do
{
while (*cpBoundary != caBoundary[0] && cpBoundary < (cpEnd-iBoundaryLen))
cpBoundary++;
if (!memcmp(cpBoundary,caBoundary,iBoundaryLen))
{
// found one!
if (cpDataStartMarker && pParam)
{
pParam->m_lContentLength = cpBoundary-cpDataStartMarker-4;
pParam->m_pData = (BYTE *)(new char[pParam->m_lContentLength+1]);
if (!pParam->m_pData)
{
EraseContent();
StartContent();
WriteTitle();
WriteContent(" Unable To Allocate Memory For MultiPart Parameter!");
EndContent();
if (bDeleteReadBuffer)
delete [] cpReadBuffer;
return FALSE;
}
memcpy(pParam->m_pData,cpDataStartMarker,pParam->m_lContentLength);
*(pParam->m_pData+pParam->m_lContentLength) = 0;
cpDataStartMarker = NULL;
}
cpBoundary += iBoundaryLen;
// check for terminating boundary
if (!memcmp(cpBoundary,"--",2))
break;
pParam = new MultiPartParam;
m_oMultiPartParams.AddTail((CObject *)pParam);
cpBoundary += 2; // skip past CR/LF
while (*cpBoundary != '\x0D' && *(cpBoundary+1) != '\x0A')
{
if (!memicmp(cpBoundary,cpContentDispTag,strlen(cpContentDispTag)))
{
cpBoundary += strlen(cpContentDispTag);
char *p = cpBoundary+1;
while (*p != ';' && *p != '\x0D')
p++;
p++;
while (*p == ' ' || *p == '\x0A')
p++;
cpBoundary = p;
}
else if (!memicmp(cpBoundary,cpNameTag,strlen(cpNameTag)))
{
cpBoundary += strlen(cpNameTag);
cpBoundary++; // skip past the qoute
char *p = cpBoundary;
while (*p != '\"')
p++;
*p = 0;
strcpy(pParam->m_caParamName,cpBoundary);
p++;
while (*p != ';' && *p != '\x0D')
p++;
p++;
while (*p == ' ' || *p == '\x0A')
p++;
cpBoundary = p;
}
else if (!memicmp(cpBoundary,cpFileNameTag,strlen(cpFileNameTag)))
{
cpBoundary += strlen(cpFileNameTag);
cpBoundary++; // skip past the qoute
char *p = cpBoundary;
while (*p != '\"')
p++;
*p = 0;
strcpy(pParam->m_caFileName,cpBoundary);
p++;
while (*p != ';' && *p != '\x0D')
p++;
p++;
while (*p == ' ' || *p == '\x0A')
p++;
cpBoundary = p;
}
else if (!memicmp(cpBoundary,cpContentTypeTag,strlen(cpContentTypeTag)))
{
cpBoundary += strlen(cpContentTypeTag);
char *p = cpBoundary+1;
while (*p != ';' && *p != '\x0D')
p++;
*p = 0;
strcpy(pParam->m_caContentType,cpBoundary);
p++;
while (*p == ' ' || *p == '\x0A')
p++;
cpBoundary = p;
}
else
{
char *p = cpBoundary+1;
while (*p != ';' && *p != '\x0D' && *p != ' ')
p++;
p++;
while (*p == ' ' || *p == '\x0A')
p++;
cpBoundary = p;
}
}
cpBoundary += 2;
// mark start for later extract of the data...
cpDataStartMarker = cpBoundary;
}
else
cpBoundary++;
}
while (cpBoundary < (cpEnd-iBoundaryLen));
if (bDeleteReadBuffer)
delete [] cpReadBuffer;
return TRUE;
}
|
|
|
|
|
I'm getting the following errors when I try to compile my code. I think it derives from the line #DEFINE INITGUID...
error C2065: 'GUID_NULL' : undeclared identifier
error C2440: 'default argument' : cannot convert from 'int' to 'const struct _GUID &'
Reason: cannot convert from 'int' to 'const struct _GUID'
No constructor could take the source type, or constructor overload resolution was ambiguous
error C2548: 'AtlAxCreateControlEx' : missing default parameter for parameter 6
error C2440: 'default argument' : cannot convert from 'int' to 'const struct _GUID &'
Reason: cannot convert from 'int' to 'const struct _GUID'
No constructor could take the source type, or constructor overload resolution was ambiguous
DOES ANYONE HAVE ANY SUGGESTIONS ON HOW I COULD HANDLE THIS??? SUGGESTIONS VERY MUCH APPRECIATED.
THANKS
|
|
|
|
|
Hello,
I'm using the following code fragment:
void CGoalsListView::OnBeginlabeledit(NMHDR* pNMHDR, LRESULT* pResult)
{
NMLVDISPINFO* pDispInfo=(NMLVDISPINFO*)pNMHDR;
CDC* pDC = GetDC();
...
long npixIndent = pDC->GetTextExtent(...).cx;
...
...and the pDC->GetTextExtent(...).cx seems to arbitrarily give different results after using the program for a while. At first, the program runs fine, and after clicking around the UI for a while, it this suddenly switches to another set of values and gives consistently larger (wrong) values.
Does anyone see something obvious here? Is the DC changing on me? I've debugged down to the GetTextExtent arguments and results, but not in to the GetTextExtent function.
thanks!
Jon Paul
|
|
|
|
|
It uses the current font, maybe that is being changed.
Jason Henderson quasi-homepage articles "Like it or not, I'm right!"
|
|
|
|
|
Jon Paul wrote:
gives consistently larger (wrong) values
Mmmhh ... As far as I know, the CSize structure is made up of two int and not long int... did you try with
int npixIndent = pDC->GetTextExtent(...).cx
This seems naive, but sometimes
Another possibility is that you changed the font size, but if the values are consistently larger , I do not think it is because if that.
~RaGE();
|
|
|
|
|
Thanks for the advice guys. I tried changing my variable to an int but that didn't change anything.
I found that the effect goes in and out every 5 or so attempts to run this code (i.e., 5 or so times with good results, and 5 with erroneous results).
Hmm......... still thinking myself, but any help would be appreciated.
thanks!
Jon Paul
|
|
|
|
|
Hi everybody,
When updating say a static text control frequently the control flickers a lot. For instance when I do this repeatedly:
wndCtrl->SetWindowText(str);
Is there a way to avoid the flickering?
Thx,
/T
|
|
|
|
|
are you do that with in a timer???????
Renjith-The CPian.
|
|
|
|
|
No, I'm reporting the progress of a lengthy process and I'm doing it withing a for loop:
for (int i=0; i<2342323346; i++)
{
DoLengthThing();
wndStaticText->SetWindowText(progress_str);
}
How can I make the static control not to flicker like crazy?
/T
|
|
|
|
|
store a copy of what you are setting the control to and only update the control if the string has changed....
|
|
|
|
|
I have an exe that I have embedded two binary files through the Resource editor in Visual C++ - How do I use those files from within the exe just like I do with Bitmaps, Icons, Cursors, Menus etc? Is there some sort of LoadResource that works for extracting custom data?
Cheers,
Clint
|
|
|
|
|
HINSTANCE hInstance = AfxGetInstanceHandle();
HRSRC hRsrc = FindResource(hInstance, pResourceIDName, "MyResourceTypeName");
if (hRsrc)
{
HGLOBAL hGlobal = LoadResource(hInstance, hRsrc);
if (hGlobal)
{
BYTE *pData = (BYTE *)LockResource(hGlobal);
DWORD dwSize = SizeofResource(hInstance, hRsrc);
..........whatever
}
UnlockResource(hGlobal);
FreeResource(hGlobal);
}
-c
Garbage collection, making life better - for weenies!
|
|
|
|
|
Hi all, I got a stupid problem regards flipping a DirectDraw surface. I have initialised DirectDraw (through CreateEx), set cooperative level and set the display mode, no probs. I can load in a graphic and blit it to the back buffer and display it by calling the flip() routine. Now heres the interesting part, if I now get the so called back buffer pointer again and draw to it, when I call flip() the page is blank. Doesn't matter what I do, its blank. I got a timer going which flips the page every 1sec, what you should see is a very small, crappy animation, but instead I get one picture and one blackness screen. great. I have looked in the DD7 SDK help and the code is very similar to mine. I get the back buffer by calling this (roughly):
LPDIRECTDRAWSURFACE7 GetBackBuffer()
{
if (NumBuffers >0)
{
LPDIRECTDRAWSURFACE7 Buffer;
DDSCAPS2 ddscaps = {DDSC_BACKBUFFER, 0, 0, 0};
PrimarySurface->GetAttachedSurface(&ddscaps, &Buffer)
return Buffer;
}
return NULL;
}
I flip the code using PrimarySurface->Flip(NULL, DDFLIP_WAIT) and have included the necessary caps (PRIMARYSURFACE, COMPLEX, FLIP, DIRECT3D, VIDEOMEMORY) and flags (BACKBUFFER etc.) in the right places (As you can see cos I can write to the back buffer and flip it, but not to the back buffer after that. Again the one after that is ok, but not the one after that etc.). Don't know what the hell it is. I have DirectX 8.1 as my runtime and 7.0 as the SDK but even still, the 7.0 sample programs work! I would be eternally greatful if someone could have a go at answering my plea for help, thanks to all those who give it a go. Also I have some trouble using high resolution 32-bit display modes (the primary surface or back buffer - I forget which - comes out as multicoloured junk when I flip it???????), the other is ok - strange eh?. Might have some connection with the other problem, maybe a memory pointer is not reallocated or something, don't know but surely someone out there has the answer...
Alan.
"When I left you I was but the learner, now I am the master" - Darth Vader
|
|
|
|
|
From my limited understanding of how page flipping works:
When you flip buffers you are actually just swapping pointers. So the back buffer becomes the primary and the primary becomes the back. If you are not re-filling the back buffer in between flippings you will get a blank page.
Alan Chambers wrote:
Also I have some trouble using high resolution 32-bit display modes (the primary surface or back buffer - I forget which - comes out as multicoloured junk when I flip it???????)
Did you convert the bitmap to 32 bit before copying it to the back buffer? Also, did you set the surface to be 32 bit? It could also be a memory thing like you said.
Jason Henderson quasi-homepage articles "Like it or not, I'm right!"
|
|
|
|
|
Thanks for your reply Jason. You're right about the pointer swapping stuff, the back buffer SHOULD become the primary and the primary SHOULD become the back buffer. But when trying to refill the back buffer here (so between flippings) it comes out blank, doesn't do it, f***s up. stupid. As for the trouble I'm having using a high resolution 32bit display (1280x1024x32), I don't even have to draw ANYTHING, just flip the back buffer and the page is full of multicoloured junk. I'm pretty sure these problems are interwined, and it looks like it may be a memory thing (not a lack of it, but the pointer system isn't doing its job properly). Should I be clearing the buffer before using it maybe? Any more ideas on how I could go about resolving it would be great, or even links to web sites that may contain the answer.
Cheers,
Alan.
"When I left you I was but the learner, now I am the master" - Darth Vader
|
|
|
|
|
Alan Chambers wrote:
As for the trouble I'm having using a high resolution 32bit display (1280x1024x32), I don't even have to draw ANYTHING, just flip the back buffer and the page is full of multicoloured junk
Be sure you use True Color in the Display settings. I had the same problems, and I changed the resolution, now it works perfectly. Also make sure, if you try to use graphs, that the correct palette was loaded, and the colorkey initialised.
Alan Chambers wrote:
But when trying to refill the back buffer here (so between flippings) it comes out blank
Once you´ve done your flip, you have to blit all the objects on the back buffer.
I´ll send you a good example, maybe it will help. Anyway, if it does not work, feel free to send me your code, i´ll throw an eye on it.
~RaGE();
|
|
|
|
|
"Send you a good example" that would be brilliant. Thanks for the advice too. I do have some added info which completes this, officially, as THE strangest problem ever. If I write the code
MessageBox(GetActiveWindow(), "Whatever", "Whatever", MB_OK) before I do any page flipping, the code works and I see this beautifully changing but crappy animation. Take it out and I get picture, blank, picture, blank etc. How stupid and strange is that! I mean what has messagebox got to do with anything? Also I notice that the primary surface always gets refreshed at application startup(made blank), whilst the back buffer retains the image that was in memory last (even if the application NEVER draws to it/clear it or anything). I take it this is normal? Many Thanks anyway Rage,
Alan.
"When I left you I was but the learner, now I am the master" - Darth Vader
|
|
|
|
|
Alan Chambers wrote:
I mean what has messagebox got to do with anything
Well, if you are running DDraw windowed, you have to define clipping regions. Anyway, mixing GDI (i.e. messageBoxes) with DDraw is not trivial, so I suppose it is not anormal that sometimes strange things come out
~RaGE();
|
|
|
|
|
I have a set of classes all derived from a single abstract base class (not CObject-based). Each of these classes can serialize itself, and does so by first calling Serialize on the base class, to serialize the common stuff.
Now, i'm adding clipboard support for these objects. I used the "clipboard assistant", which is uses CArchive to store the objects. Storing them on the clipboard is easy, just serialize out. So far so good. But going the other way, creating an object based on data from the clipboard, is where I'm stuck. I can't just serialize to my derived objects because I don't know which one to use - all I know is that I have a chunk of serialized data that came from one of my derived classes. I can't serialize to the base class because it's abstract.
Part of what the base class serializes is a tag that identifies the derived class type. But, I can't read into that CArchive to find the tag, then rewind, because CArchive doesn't have any "rewind" functionality (though its CFile member probably does).
Any ideas?
-c
Garbage collection, making life better - for weenies!
|
|
|
|
|
Not like you to be posting questions Chris, you normally answer mine. I'm a little shakey answering this cos I'm not really sure if its what your after, but it may at least give you an idea. Have you tried using fstream to read in the first struct/value of your file and based on that use a case statement to process the correct CArchive and serialize routine? I'm not that clued up about MFC but I think your in a bit of a catch 22. If I'm on the right lines, I'd be happy to help a bt further.
Alan.
"When I left you I was but the learner, now I am the master" - Darth Vader
|
|
|
|
|
Alan Chambers wrote:
Not like you to be posting questions Chris,
yeah, there are some things i just never do much of - this is one of them.
looks like i'll end up doing something like what you're describing. i was hoping for a cleaner way. oh well.
-c
Garbage collection, making life better - for weenies!
|
|
|
|
|
Chris, see my 3rd serialization article, specifically the section "Serializing a heterogenous collection class". I have sample code that uses the factory pattern to implement this. Send me mail if you'd like me to send it to you (virtual NDA assumed ).
/ravi
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|