globals in unmanaged space

M

marek

Hello All,

we are doing a quite a big project that contains at
the lowest level an unmenaged c++ classes. Above it there
are managed wrappers and at the top there are ASP.NET
pages. Can anyone tell me how to force ASP.NET not
to "clear" or reinitialize unmenaged global or static
variables that are set on unmanaged level between
successive requests?

To be more clear: currenly every global variable from
unmanaged heap that gets changed from within any umnamaged
method gets reinitialized on the next request. I'm
particularly interested in keeping intact some global
pointers - currently they get NULL on successive
requests thoungh destructors of objects that they pointed
before request are not called i.e. the objects somehow are
lost.

Any advice is appreciated.
Greetings
Marek
 
G

George Ter-Saakov

..NET does not affect unmanaged variables.
How can it? it has no information about them?

Most likely it's a problem in C++ classes. How do you call your C++
classes?

Are they COM objects or wrapped into DLL calls?

George.
 
M

marek

Hi,

thanks for reply.

We have a full control on unmanaged code. Basically all
managed classes that are used on aspx pages look like that
presented below

#include "Unmanaged/User.h"

namespace ManagedWrappers
{
__gc public class CUserWrp
{
public:
CUserWrp(String login, String password);
virtual ~CUserWrp();
CUserWrp* GetUser();

private:
CUser* m_pUserCtr; // unmanaged member
};
}

We have some globals in a cpp file where unmanaged CUser
is defined. This file together with the other unamanaged
stuff is compiled to Unmanaged.lib and then linked to
ManagedWrappers.dll and finally with *.cs files to
TheWholeProject.dll.

Globals are initialized on a call from a page i.e. a full
file path of the default.aspx page is retrieved on
global.asax and passed to unmanaged space by some
unmanaged method. Then the other function from the page
(but still on that first request) is able to call another
unamanged method that uses aproprietly set globals within
unmanaged space.

Than when the next request comes in all the globals are
reset - pointers are set to NULL. I thought that when it's
basically the same thread space (TheWholeProject.dll) the
unmanaged space will not be reset. By default it seems to
be. But I believe it is possible somehow to have it
unchanged on the next request - or I'm wrong and have to
reprogram quite a bit of code.

Any advice appreciated
Greetings
Marek
 
G

George Ter-Saakov

The only thing i can think of is following.

The DLL which is using managed and unmanaged classes is called mixed mode
DLL

Usually with unmanaged DLL C++ runtime must be initialized first.
Also C++ runtime initializes global variables.
In regular DLL/EXE compiler sets entry point to initlization routine and
then execution goes to DllMain/WinMain


When .NET calls mixed mode DLL it ignores the entry point set by compiler
and using it's own (.NET ) entry point.

So you must initialize C++ runtime manually.

So my guess you do it (initialize C++ runtime) on each browser request as
opppose to do it only once.

George.
 
M

marek

Yeah I think your advice will solve the problem helpful.
I'll check it tomorrow.

BTW - where can I read about this entry point stuff as you
wrote? Is it really true? If they just ignore an entry
point for mixed dlls it's just a horrible hole. Maybe it's
possible to force .net somehow not to ignore it just like
that ...


Thanks anyway.
waiting for further comments
Greetings
Marek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top