I have a mainapplication, that loads a DLL - this DLL has a callback
function, which retrieves the address of a Class i have defined in the
mainapplication, which contains all global-allocations.

Now this works fine when im calling functions etc. from my DLL - but i get
an access violation as soon as i try to enter a critical section from this
class in the mainapp.

// in main

class __cGlobalClass
{
public:
CRITICAL_SECTION my_criticalsection_ole;
}

// in DLL
// MainGlobalClass this is a pointer to the __cGlobalClass in the main
(exchanged by a function).

....
......
EnterCriticalSection(&MainGlobalClass->m_CriticalSection_ole);

This causes an acces-violation......"write of address 0x00000010".

Its strange, because everything other than the critical_section is working
ok - do any of you have any suggestions ?

Re: Critical section from DLL by Doug

Doug
Wed Mar 03 17:30:42 CST 2004

verbartime wrote:

>I have a mainapplication, that loads a DLL - this DLL has a callback
>function, which retrieves the address of a Class i have defined in the
>mainapplication, which contains all global-allocations.
>
>Now this works fine when im calling functions etc. from my DLL - but i get
>an access violation as soon as i try to enter a critical section from this
>class in the mainapp.
>
>// in main
>
>class __cGlobalClass
>{
> public:
> CRITICAL_SECTION my_criticalsection_ole;
>}
>
>// in DLL
>// MainGlobalClass this is a pointer to the __cGlobalClass in the main
>(exchanged by a function).
>
>....
>......
>EnterCriticalSection(&MainGlobalClass->m_CriticalSection_ole);
>
>This causes an acces-violation......"write of address 0x00000010".
>
>Its strange, because everything other than the critical_section is working
>ok - do any of you have any suggestions ?

Have you called InitializeCriticalSection? You can do this in your class's
ctor and call DeleteCriticalSection in its dtor. Be sure to disable copying
of the class by declaring but not defining private copy ctor and assignment
operator.

P.S. Don't make up names containing two underscores in a row, as they are
all reserved. In general, avoid names beginning with the underscore, as they
are mostly all reserved, unless you can recite the rules which govern their
use.

--
Doug Harrison
Microsoft MVP - Visual C++

Re: Critical section from DLL by Igor

Igor
Wed Mar 03 17:32:23 CST 2004

"verbartime" <verbatim@vfreds.tk> wrote in message
news:uoICHZXAEHA.2036@TK2MSFTNGP12.phx.gbl...
> I have a mainapplication, that loads a DLL - this DLL has a callback
> function, which retrieves the address of a Class i have defined in the
> mainapplication, which contains all global-allocations.
>
> Now this works fine when im calling functions etc. from my DLL - but i
get
> an access violation as soon as i try to enter a critical section from
this
> class in the mainapp.
>
> // in main
>
> class __cGlobalClass
> {
> public:
> CRITICAL_SECTION my_criticalsection_ole;
> }
>
> // in DLL
> // MainGlobalClass this is a pointer to the __cGlobalClass in the main
> (exchanged by a function).
>
> ....
> ......
> EnterCriticalSection(&MainGlobalClass->m_CriticalSection_ole);
>
> This causes an acces-violation......"write of address 0x00000010".
>
> Its strange, because everything other than the critical_section is
working
> ok - do any of you have any suggestions ?

Are you calling InitializeCriticalSection anywhere? You should, you
know.
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken



Re: Critical section from DLL by verbartime

verbartime
Wed Mar 03 17:54:41 CST 2004

Yes, InitializeCriticalSection is done in the constructor. So im sure that
its initialized before i pass the address to the DLL.

And im not assigning classes - i just use the pointer and address myself
this way.

What can it be ? is there something about criticalsections from DLL's ? it
should be the same address space when i load it with LoadLibrary ?



Re: Critical section from DLL by verbartime

verbartime
Wed Mar 03 18:25:31 CST 2004

damn...somehow its working now ? im not quite sure what i did - really didnt
change anything.

So maybe it appears again, maybe it doesnt - i thank you for your help
anyway.



Re: Critical section from DLL by verbartime

verbartime
Wed Mar 03 19:08:48 CST 2004

okay...

it appears that somehow my addressing has gone awry, passing the pointer
from the main to the DLL - not quite there yet, but somehow its not going
ok...



Re: Critical section from DLL by Ivan

Ivan
Wed Mar 03 20:12:16 CST 2004

The construction order of static and global objects
is implementation dependent per standard.
Certain implmentations conserve the declaration order as the initialization
order,
but this is only true for a single compilaiton unit.
Are you sure you are not relying on an undefined behavior to achieve
something ?

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of any included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


"verbartime" <verbatim@vfreds.tk> wrote in message
news:O86XAVYAEHA.1456@TK2MSFTNGP09.phx.gbl...
> okay...
>
> it appears that somehow my addressing has gone awry, passing the pointer
> from the main to the DLL - not quite there yet, but somehow its not going
> ok...
>
>