A
Allen
Hi all,
I tried posting to one of the ms.win32 groups and haven't gotten a
response yet. It may be my C++ that's at fault anyway so I'll try here too.
I wrote a .dll that is misbehaving (access violation at startup) and I
can't find the problem. I'm using load time linking and, when I try to step
into program execution to find the problem, I don't even get to the start of
WinMain before it throws the exception. The source files are a little too
big to post here but, I'll send them to any who are willing to take the time
to help me. I suspect it's something dumb that I either overlooked or
didn't know about. I'm not a professional and I've never taken any
programming classes so please don't laugh too hard! I'm still sort of new
at this.
--
Best wishes,
Allen
No SPAM in my email !!
Here are some of the sections where I suspect the problem might be.
//commandmain.cpp--main .dll file
#include "CmdBuffer.h"
PCCOMMANDBUF pcbCommandBuf = new CCommandBuffer("concmd.ngc");
/*since the exception is thrown immediatly upon loading, I think this "new"
might be the problem. I have another .dll that works fine though and it
does almost the exact same thing*/
EXPORT int ExecCmdLine(PCOMMANDMSG pCmdMsg, DWORD dwExecFlags=0)
{
return pcbCommandBuf->CBExec(pCmdMsg, dwExecFlags);
}
//end excerpt
//CmdBuffer.h--header for CCommandBuffer
class CCommandBuffer : CCommandList
{
public:
CCommandBuffer(char* pszInitialLibrary);
~CCommandBuffer();
int CBExec(PCOMMANDMSG pCmdMsg, DWORD dwExecFlags);
int CBPopBuf();
int CBFlushBuf();
private:
int CB_iMaxCount;
int CB_iCmdCount;
int CB_iExecIndex;
PCOMMANDMSG CB_pcmCmdBuf;
int AllocBuf();
int PopIndex();
int PushIndex();
int QueueBuf(PCOMMANDMSG pCmdMsg);
int PushBuf(PCOMMANDMSG pCmdMsg);
};
//end excerpt
//CmdBuffer.cpp--main source for CCommandBuffer
#include "CmdBuffer.h"
#include "..\util.h"
CCommandBuffer::CCommandBuffer(char* pszLibrary) :
CCommandList(pszLibrary)
{
CB_iCmdCount = 0;
CB_iMaxCount = 0;
CB_iExecIndex = 0;
AllocBuf();
}
int CCommandBuffer::AllocBuf()
{
PCOMMANDMSG pcmTemp;
//don't overwrite MaxCount yet, PopIndex needs it
int iTempMaxCount = CB_iMaxCount < CMDBUF_MIN_ELEMENTS ?
CMDBUF_MIN_ELEMENTS : CB_iMaxCount+2;
pcmTemp = (PCOMMANDMSG)LocalAlloc(LPTR, sizeof(CommandMsg) *
iTempMaxCount);
if(pcmTemp == NULL)
{
Write_Error("\nCCommandBuffer::AllocBuf() memory allocation
failed");
return ERROR_FATAL;
}
//copy current cmds to new buffer--must end up sequential
if(CB_pcmCmdBuf)
{
for(int i=0; i < CB_iCmdCount; i++)
memcpy((void*)&pcmTemp, (void*)&CB_pcmCmdBuf[PopIndex()],
sizeof(CommandMsg));
}
CB_iExecIndex = 0;
CB_iMaxCount = iTempMaxCount; //ok, now overwrite
if(CB_pcmCmdBuf)
delete CB_pcmCmdBuf;
CB_pcmCmdBuf = pcmTemp;
return OK;
}
//end excerpt
I tried posting to one of the ms.win32 groups and haven't gotten a
response yet. It may be my C++ that's at fault anyway so I'll try here too.
I wrote a .dll that is misbehaving (access violation at startup) and I
can't find the problem. I'm using load time linking and, when I try to step
into program execution to find the problem, I don't even get to the start of
WinMain before it throws the exception. The source files are a little too
big to post here but, I'll send them to any who are willing to take the time
to help me. I suspect it's something dumb that I either overlooked or
didn't know about. I'm not a professional and I've never taken any
programming classes so please don't laugh too hard! I'm still sort of new
at this.
--
Best wishes,
Allen
No SPAM in my email !!
Here are some of the sections where I suspect the problem might be.
//commandmain.cpp--main .dll file
#include "CmdBuffer.h"
PCCOMMANDBUF pcbCommandBuf = new CCommandBuffer("concmd.ngc");
/*since the exception is thrown immediatly upon loading, I think this "new"
might be the problem. I have another .dll that works fine though and it
does almost the exact same thing*/
EXPORT int ExecCmdLine(PCOMMANDMSG pCmdMsg, DWORD dwExecFlags=0)
{
return pcbCommandBuf->CBExec(pCmdMsg, dwExecFlags);
}
//end excerpt
//CmdBuffer.h--header for CCommandBuffer
class CCommandBuffer : CCommandList
{
public:
CCommandBuffer(char* pszInitialLibrary);
~CCommandBuffer();
int CBExec(PCOMMANDMSG pCmdMsg, DWORD dwExecFlags);
int CBPopBuf();
int CBFlushBuf();
private:
int CB_iMaxCount;
int CB_iCmdCount;
int CB_iExecIndex;
PCOMMANDMSG CB_pcmCmdBuf;
int AllocBuf();
int PopIndex();
int PushIndex();
int QueueBuf(PCOMMANDMSG pCmdMsg);
int PushBuf(PCOMMANDMSG pCmdMsg);
};
//end excerpt
//CmdBuffer.cpp--main source for CCommandBuffer
#include "CmdBuffer.h"
#include "..\util.h"
CCommandBuffer::CCommandBuffer(char* pszLibrary) :
CCommandList(pszLibrary)
{
CB_iCmdCount = 0;
CB_iMaxCount = 0;
CB_iExecIndex = 0;
AllocBuf();
}
int CCommandBuffer::AllocBuf()
{
PCOMMANDMSG pcmTemp;
//don't overwrite MaxCount yet, PopIndex needs it
int iTempMaxCount = CB_iMaxCount < CMDBUF_MIN_ELEMENTS ?
CMDBUF_MIN_ELEMENTS : CB_iMaxCount+2;
pcmTemp = (PCOMMANDMSG)LocalAlloc(LPTR, sizeof(CommandMsg) *
iTempMaxCount);
if(pcmTemp == NULL)
{
Write_Error("\nCCommandBuffer::AllocBuf() memory allocation
failed");
return ERROR_FATAL;
}
//copy current cmds to new buffer--must end up sequential
if(CB_pcmCmdBuf)
{
for(int i=0; i < CB_iCmdCount; i++)
memcpy((void*)&pcmTemp, (void*)&CB_pcmCmdBuf[PopIndex()],
sizeof(CommandMsg));
}
CB_iExecIndex = 0;
CB_iMaxCount = iTempMaxCount; //ok, now overwrite
if(CB_pcmCmdBuf)
delete CB_pcmCmdBuf;
CB_pcmCmdBuf = pcmTemp;
return OK;
}
//end excerpt