|
Hi All,
I'm having a bit of trouble adding derived objects of CObject to a CObArray object. I get the following error:
error C2243: 'type cast' : conversion from 'DoobyObj *__w64 ' to 'CObject *' exists, but is inaccessible
This is just a test for a later prject (hence the stupid class name). I need the DoobyObj class to inherit from CObject class so that I can serialize the CObArray object.
The error occurs on the Add line:
void SerObject::addDoobyObject(DoobyObj dO)
{
obaObjects.Add(&dO); //CObArray
resetIndex();
}
Here is the definition of DoobyObj:
class DoobyObj : CObject
{
public:
DECLARE_SERIAL( DoobyObj )
DoobyObj();
void Serialize(CArchive& archive );
CString dooby;
};
Can anyone solve my problem??
Thanks,
Donal
|
|
|
|
|
Are you compiling for 64-bit Windows, by any chance? I'm not sure MFC works with 64-bit Windows yet... It might, but that may be the reason
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
No, just windows 2K.
Do I need to setup some type of conversion method in my CObject derived calss?
|
|
|
|
|
Sorry for the delay. I haven't been able to access CP for almost two weeks
I should have picked up this before...
You are inheriting CObject as private, which implicitly makes any CObject methods private. This means that CArray can not access the implicit CObject* conversion because it is private.
Instead of
class DoobyObj : CObject
use
class DoobyObj : public CObject
This should fix the problem
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Hello everybody,
I hope you can help me with my problem.
At this moment I am developping a project in DirectSound. I need to play a wave file. Because of future enhancements the wave file is played with DirectSound.
I use 3D buffers and the extended waveformat. All initialisation goes well, but when I try to lock the buffer the error DSERR_PRIOLEVELNEEDED is returned. I checked the SetCooperativeLevel function and that returns DS_OK.
The code I use for those two functions look like this:
<br />
MainhWnd = GetSafeHwnd();<br />
hr = m_pDS->SetCooperativeLevel(MainhWnd, DSSCL_NORMAL);<br />
<br />
....<br />
<br />
VOID* pbData = NULL;<br />
VOID* pbData2 = NULL;<br />
DWORD dwLength;<br />
DWORD dwLength2;<br />
int lPos=0;<br />
DWORD m_dwBufferBytes;<br />
<br />
hr= m_pDSBuffer->Lock(lPos, m_dwBufferBytes, &pbData, &dwLength, &pbData2, &dwLength2, 0);<br />
Does anyone know what the problem is, or how I can solve this.
Thanks in advance,
Miepmuts
|
|
|
|
|
Already tried with a higher level within SetCooperativeLevel ?
~RaGE();
|
|
|
|
|
Yes I tried to change the Cooperative Level to DSSCL_PRIORITY in combination with the SetFormat function. But that gives the same result, also another window handle doesn't change a thing.
|
|
|
|
|
I suppose DSBLOCK_ENTIREBUFFER is equal to 0, since you are giving 0 as last parameter of your function. If not, then this will attempt to lock a buffer which can have any size, since m_dwBufferBytes is not initialised, causing the lock to fail randomly.
~RaGE();
|
|
|
|
|
It's not a random error but every time the same one: DSERR_PRIOLEVELNEEDED
Even when I fill in those two variables the function returns the same error.
It is a very strange error. I asked someone at my work, and even he didn't see a solution.
|
|
|
|
|
It must be something you are doing inbetween the code lines you have posted.
~RaGE();
|
|
|
|
|
Allright then. Here it goes:
<br />
hr = DirectSoundCreate(NULL, &m_pDS, 0);<br />
if(hr == DS_OK)<br />
{<br />
HWND MainhWnd;<br />
MainhWnd = GetSafeHwnd();<br />
hr = m_pDS->SetCooperativeLevel(MainhWnd, DSSCL_NORMAL);<br />
if(hr == DS_OK)<br />
{<br />
DSBUFFERDESC bufferDesc;<br />
memset(&bufferDesc, 0, sizeof(DSBUFFERDESC));<br />
bufferDesc.dwSize = sizeof(DSBUFFERDESC);<br />
bufferDesc.dwFlags = DSBCAPS_PRIMARYBUFFER | DSBCAPS_GETCURRENTPOSITION2 ;<br />
bufferDesc.dwBufferBytes = 0;<br />
bufferDesc.lpwfxFormat = NULL;<br />
hr = m_pDS->CreateSoundBuffer(&bufferDesc, &m_pPrimaryBuffer, NULL);<br />
if(hr == DS_OK)<br />
{<br />
hr = m_pPrimaryBuffer->QueryInterface( IID_IDirectSound3DBuffer, (void**) &m_pDS3DBuffer );<br />
WAVEFORMATEXTENSIBLE formatex;<br />
memset(&formatex, 0, sizeof(WAVEFORMATEXTENSIBLE));<br />
formatex.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;<br />
formatex.Format.nChannels = 4;<br />
formatex.Format.nSamplesPerSec = 44100;<br />
formatex.Format.nAvgBytesPerSec = 352800;<br />
formatex.Format.nBlockAlign = 8;<br />
formatex.Format.wBitsPerSample = 16;<br />
formatex.Format.cbSize = 22;<br />
formatex.Samples.wValidBitsPerSample = 16;<br />
formatex.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT<br />
| SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT;<br />
formatex.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;<br />
DSBUFFERDESC bufferSec;<br />
memset(&bufferSec, 0, sizeof(bufferSec));<br />
bufferSec.dwSize = sizeof(bufferSec);<br />
bufferSec.dwFlags = DSBCAPS_GETCURRENTPOSITION2;<br />
bufferSec.lpwfxFormat = &waveformat;<br />
hr = m_pDS->CreateSoundBuffer(&bufferDesc, &m_pDSBuffer, NULL);<br />
}<br />
}<br />
<br />
HRESULT hr;<br />
BYTE* pbWavData;<br />
UINT cbWavSize;<br />
VOID* pbData = NULL;<br />
VOID* pbData2 = NULL;<br />
DWORD dwLength;<br />
DWORD dwLength2;<br />
<br />
int nWaveFileSize = ckIn.cksize;<br />
pbWavData = new BYTE[nWaveFileSize];<br />
if(pbWavData == NULL)<br />
{<br />
return 0;<br />
}<br />
MMIOINFO mmioinfoIn;<br />
<br />
cbWavSize = 0;<br />
if(mmioGetInfo(hmmioIn, &mmioinfoIn, 0) != 0)<br />
{<br />
return 0;<br />
}<br />
UINT cbDataIn = nWaveFileSize;<br />
if(cbDataIn > ckIn.cksize)<br />
{<br />
cbDataIn = ckIn.cksize;<br />
}<br />
ckIn.cksize -= cbDataIn;<br />
<br />
for(DWORD ct = 0; ct < cbDataIn; ct++)<br />
{<br />
if(mmioinfoIn.pchNext == mmioinfoIn.pchEndRead)<br />
{<br />
if(mmioAdvance(hmmioIn, &mmioinfoIn, MMIO_READ) != 0)<br />
{<br />
return 0;<br />
}<br />
if(mmioinfoIn.pchNext == mmioinfoIn.pchEndRead)<br />
{<br />
return 0;<br />
}<br />
}<br />
<br />
*((BYTE*)pbWavData + ct) = *((BYTE*)mmioinfoIn.pchNext);<br />
mmioinfoIn.pchNext++;<br />
}<br />
if(mmioSetInfo(hmmioIn, &mmioinfoIn, 0) != 0)<br />
{<br />
return 0;<br />
}<br />
cbWavSize = cbDataIn;<br />
m_dwBufferBytes = 8 * 1024;<br />
<br />
StartDataRead(&m_ckIn);<br />
int lPos=0;<br />
hr= m_pDSBuffer->Lock(lPos, m_dwBufferBytes, &pbData, &dwLength, &pbData2,&dwLength2, DSBLOCK_ENTIREBUFFER);<br />
if( hr != DS_OK)
{<br />
return 0;<br />
}<br />
<br />
memcpy(pbData, pbWavData, m_dwBufferBytes);<br />
m_pDSBuffer->Unlock(pbData, m_dwBufferBytes, NULL, 0);<br />
pbData = NULL;<br />
return 1;<br />
<br />
I hope you can do something with this. There is a part of code in between of initialising the mmio and the chunks.
|
|
|
|
|
Is it possible to run GCC within Microsoft's IDE (6 or .NET, it doesn't matter which), I just want to test some template code.
I know that it is possible because comeau and the intel compiler do it, but has anyone seen it for GCC.
thanks
|
|
|
|
|
Try the following links.
http://sources.redhat.com/ml/crossgcc/2001-05/msg00046.html
http://www.cygwin.com/ml/crossgcc/2001-09/msg00069.html
-Tareq
|
|
|
|
|
Hello
Does anyone know a url where i can find an extensively comparison between Visual C++ 5.0 and the 6.0 version? Like for example: 6.0 version had this as advantage, this as disadvantage etc
Greetings
Jens
|
|
|
|
|
I just spent the best part of today finding a nasty little bug and thought I might "share" with you.
We had some code that basically went
{<br />
CPen apen;<br />
apen.CreatePen(...);<br />
dc->SelectObject(&apen);<br />
<br />
<br />
dc->SelectStockObject(BLACK_PEN);
}
Last version, the code was changed to something like
{<br />
if (option)<br />
{<br />
CPen apen;<br />
apen.CreatePen(...);<br />
dc->SelectObject(&apen);<br />
<br />
}<br />
else<br />
{<br />
CPen bpen;<br />
bpen.CreatePen(...);<br />
dc->SelectObject(&bpen);<br />
<br />
}<br />
dc->SelectStockObject(BLACK_PEN);
}
I am sure you can see the error... apen and bpen are now being destroyed before selected out. Resource leak.
Running this code on Win2000/XP is fine because they clean up the mess. Running on 95,98,ME caused massive resource leaks (obviously!) The error is obvious when simplified as above but it was not the least bit obvious in the production code.
It's always the simple things that bite you!
Paul Hooper
If you spend your whole life looking over your shoulder, they will get you from the front instead.
|
|
|
|
|
CPen* pOldPen = dc->SelectObject(&apen);
//Do lots of work with dc
dc->SelectObject(pOldPen);
or you could just use SaveDC() and RestoreDC() so you do not have to keep track of what objects are selected.
int nSavedDC = dc->SaveDC();
dc->SelectObject(&apen);
//Do lots of work with dc
dc->RestoreDC(nSavedDC);
Trust in the code Luke. Yea right!
|
|
|
|
|
Oh! One more thing, do not do this:
if(..)
{
CPen apen;
....
dc->SelectObject(&apen);
}
Unless you are going to restore the old pen before leaving the 'if' block, because (of course) apen goes out of scope as soon as you leave the block.
CPen apen;
if(..)
{
....
dc->SelectObject(&apen);
}
Also it you must use CPen::CreatePen(), instead of the constructor, to create your pens then you must call CPen::DeleteObject() to destroy it or you will get memory leaks.
Trust in the code Luke. Yea right!
|
|
|
|
|
Hi,
In a dialog based application (main application window), a frame window
can be drived by click a menu item. Now my problem is that i want use some functions defined at the appDlg.cpp, how should i call these functions in myframe.cpp? How the communications are constructed ?
Thanks in advance!
chen
|
|
|
|
|
Three solutions :
1. Use user defined messages with SendMessage or PostMessage .
2. Overwrite the Create (Or DoModal ) function of the frame window to add a pointer to a CYourDialog (where CYourDialog is the name of your dialog) as parameter. Put a member variable m_pMainDlg in your Frame window class, and store the pointer in it. Call your base class functions with
m_pMainDlg->Function1();
3.[MFC] Use AfxGetMainWnd() in a type cast :
CYourDialog *m_pMainDialog = (CYourDialog*)AfxgetMainWnd();
m_pMainDlg->Function1();
~RaGE();
|
|
|
|
|
Hello....
I am having problems when I am trying to drag and drop one of my activeX control from an application to MS-WORD.
The problem is that I am not sure what format it is for an ActiveX Control in clipboard (ie. CF_TEXT is for text) so I dont know what to put as the first parameter in the function when I need to cashe my data into the global memory created ....
"opOleDataSource->CacheGlobalData(??????, hGlobal);"
Does anyone knows how to do this and Please advise me !!
Thank You !!
|
|
|
|
|
I have some problems with my code here. You can see where the error appears in the code:
char szCommand[] = "luc 192.168.244.151 5000 50 mypass";
void HotIceParser(const char* command, PHIPD phipd)
{
char buffert[20+1] = {0};
char* p1 = NULL;
char* p2 = NULL;
#ifdef DEBUG_MODE
assert(phipd != NULL);
#endif
p1 = &buffert[0];
p2 = &command[0];
while((*p2 != ' ') && (*p2 != '\0'))
*p1++ = *p2++;
MessageBox(NULL, buffert, "1",MB_OK);
if(strcmp(buffert,"luc") == 0)
{
phipd->type = LUC;
p1 = &buffert[0];
p2++;
while((*p2 != ' ') && (*p2 != '\0'))
*p1++ = *p2++;
MessageBox(NULL, buffert, "2",MB_OK);
strcpy(phipd->luc.pszIP, buffert);
}
}
Can you help me to solve this?
Rickard Andersson8
Here is my card, contact me later!
UIN: 50302279
E-Mail: nikado@pc.nu
Interests: C++, ADO, SQL, Winsock, 0s and 1s
|
|
|
|
|
Do you really NEED to use C? Your line
char buffert[20+1] = {0};
seems to be C++ to me: I C, you would use zeromem() or memset().
But if using plain, ugly C is not of prime importance, because you use a C++-compiler anyway, you can just as well use std::string to do the parsing:
void HotIceParser(const char* cmd, PHIPD phipd)
std::string command( cmd );
std::string::iterator p1 = command.find_first_not_of(' \0'); ..and so on..
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
jhwurmbach wrote:
Do you really NEED to use C
Hm... in fact no. But I want to learn it.
jhwurmbach wrote:
char buffert[20+1] = {0};
seems to be C++ to me:
I C, you would use zeromem() or memset().
Thanks!
I want perfect C code!
Rickard Andersson8
Here is my card, contact me later!
UIN: 50302279
E-Mail: nikado@pc.nu
Interests: C++, ADO, SQL, Winsock, 0s and 1s
|
|
|
|
|
char buffert[20+1] = {0};
This is C. When you initialise a buffer like this the buffer is initialised to all zeros.
char buffert[20+1] = {'\0'};
or
char buffert[20+1] = {(char)0};
is more correct.
char buffer[4] = {'1'} produces a buffer containing the follwing:
'1','\0','\0','\0'
Trust in the code Luke. Yea right!
|
|
|
|
|
I am presuming that you are sending szCommand to the function. szCommand is longer than 20 characters and buffert will only hold 20. Your while loop will keep filling buffert past the 21 limit of your array and corrupt whatever is around.
You need to check that your command parameter is not bigger than buffert.
Paul Hooper
If you spend your whole life looking over your shoulder, they will get you from the front instead.
|
|
|
|
|