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[i], (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 9 2812
Also look out for the insidious "standard" on Windows that memory allocated
by one DLL can't be deleted by another DLL of app (causes an access
violation).
So if the DLL has got this function:
void dll_test (std::vector<std::string> vec)
{
vec.push_back("TEST"); // Memory for string "TEST" allocated by DLL here
}
and you call this from an app that uses the DLL:
void my_test()
{
std::vector<std::string> myvec
dll_test (myvec);
} // Memory for myvec and "TEST" string deleted by app here
You will get an access violation.
RCS
"Allen" <al************@att.SPAM.net> skrev i melding
news:%9*********************@bgtnsc05-news.ops.worldnet.att.net... 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[i], (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
> void dll_test (std::vector<std::string> vec) <----- OOPS, typo { vec.push_back("TEST"); // Memory for string "TEST" allocated by DLL
here }
That should be:
void dll_test (std::vector<std::string>& vec)
{
vec.push_back("TEST"); // Memory for string "TEST" allocated by DLL
here
}
On Fri, 15 Aug 2003 13:52:43 +0200, "RCS" <rc****@online.no> wrote: Also look out for the insidious "standard" on Windows that memory allocated by one DLL can't be deleted by another DLL of app (causes an access violation).
That's not a "standard", and it is in fact 100% incorrect.
You need to know what you're doing when programming on any
platform.
If you do things correctly, regardless of platform, then there is
no such problem as you describe; otherwise, there is. The details
just concern tool usage and so are off-topic in this group. For
more information visit the os-specific groups, comp.os.*.
"Alf P. Steinbach" <al***@start.no> skrev i melding
news:3f***************@News.CIS.DFN.DE... On Fri, 15 Aug 2003 13:52:43 +0200, "RCS" <rc****@online.no> wrote:
Also look out for the insidious "standard" on Windows that memory
allocatedby one DLL can't be deleted by another DLL of app (causes an access violation). That's not a "standard", and it is in fact 100% incorrect.
That's why I said "standard", and not standard :-).
And in fact, it's 100% correct (on Windows, that is).
You need to know what you're doing when programming on any platform.
Pretty obvious, isn't it?
That's why, as a help, I pointed out that on the platform WINDOWS you can
get into trouble if you delete memory allocated by a DLL outside the DLL,
and this is one of the things one need to know when programming for Windows
(using Visual C++).
If you do things correctly, regardless of platform, then there is no such problem as you describe; otherwise, there is.
What does this mean? You might as well have said: "If you stand on your
head, your feet is in the air, otherwise they don't"
just concern tool usage and so are off-topic in this group. For more information visit the os-specific groups, comp.os.*.
The problems Allen reported could be os-spesific (for Windows). That's why I
mentioned an possible os-spesific source of troubles.
RCS
> >Also look out for the insidious "standard" on Windows that memory
allocated by one DLL can't be deleted by another DLL of app (causes an access violation).
Things like this may happen if - and only if - you statically link your EXE
against RT libs and dynamically link your DLL against RT libs...
> And in fact, it's 100% correct (on Windows, that is).
It's 100% wrong - see my prev posting. When things like this happen it's
your fault...
"Christian Janßen" <cj@christian-janszen.de> skrev i melding
news:3f********@news.arcor-ip.de... And in fact, it's 100% correct (on Windows, that is).
It's 100% wrong - see my prev posting. When things like this happen it's your fault...
No, it's your fault :-)
RCS
> No, it's your fault :-)
Mine? It works like expected here. No problems. So if _you_ have
difficulties with this, it _must_ be your mistake!
"Christian Janßen" <cj@christian-janszen.de> skrev i melding
news:3f********@news.arcor-ip.de... No, it's your fault :-)
Mine? It works like expected here. No problems. So if _you_ have difficulties with this, it _must_ be your mistake!
Hey, I was only trying to be funny :-)
RCS This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: jason |
last post by:
Hi Ray...a while ago you explained an elegant solution to enable me to
CREATE and EDIT existing tables and queries inside my online access 2000
database.... could you provide refresher links on...
|
by: Torbjørn Pettersen |
last post by:
I've started cleaning up my HTML and implementing CSS. So far I've
used FrontPage, but am switching over to DreamWeaver.
Reading a bit on W3Schools.com and W3.org I see there are a lot
of HTML...
|
by: wilson |
last post by:
Hi All,
I am a novice at C and just have learned pointer for a short period.
Today one error had occured while executing my program below.
And I cannot find the error out since it's checked "OK"...
|
by: Suyog_Linux |
last post by:
I wish to know how the free()function knows how much memory to be
freed as we only give pointer to allocated memory as an argument to
free(). Does system use an internal variable to store allocated...
|
by: v4vijayakumar |
last post by:
'continue' within switch actually associated with the outer 'while'
loop. Is this behavior protable?
int ch = '\n';
while (true) {
switch(ch) {
case '\n': cout << "test"; continue;
}
}
|
by: zl2k |
last post by:
hi, there
I am using a big, sparse binary array (size of 256^3). The size may be
changed in run time. I first thought about using the bitset but found
its size is unchangeable. If I use the...
|
by: OziRus |
last post by:
Hi,
This is my first message on this group. I want to ask something about
screen-drawing functions. I wrote and compiled below code succesfully
on TC IDE in Win-xp. Then i tried to work it on...
|
by: ivan |
last post by:
hi all,
if I have:
if(A && B || C)
which operation gets executed first?
If I remeber well should be &&, am I correct?
thanks
|
by: BobaBird |
last post by:
When <liis set to {max-width:45em;}, the bullets move from the top
to the bottom of the <li>. Also, the bullet for a top-level <liends
up on the same line as the last <liof its nested list, with...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |