By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,965 Members | 1,457 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,965 IT Pros & Developers. It's quick & easy.

globals in unmanaged space

P: n/a
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

Nov 18 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
..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.

"marek" <ma***@wp.pl> wrote in message
news:0d****************************@phx.gbl...
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

Nov 18 '05 #2

P: n/a
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
-----Original Message-----
..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.

"marek" <ma***@wp.pl> wrote in message
news:0d****************************@phx.gbl...
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

.

Nov 18 '05 #3

P: n/a
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.

"marek" <ma***@wp.pl> wrote in message
news:01****************************@phx.gbl...
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
-----Original Message-----
..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.

"marek" <ma***@wp.pl> wrote in message
news:0d****************************@phx.gbl...
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

.

Nov 18 '05 #4

P: n/a
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
-----Original Message-----
The only thing i can think of is following.

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

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 andthen execution goes to DllMain/WinMain
When .NET calls mixed mode DLL it ignores the entry point set by compilerand 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 asopppose to do it only once.

George.

"marek" <ma***@wp.pl> wrote in message
news:01****************************@phx.gbl...
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
>-----Original Message-----
>..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.
>
>"marek" <ma***@wp.pl> wrote in message
>news:0d****************************@phx.gbl...
>> 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
>>
>
>
>.
>

.

Nov 18 '05 #5

P: n/a
May be this article will help.

http://msdn.microsoft.com/library/de...omixedmode.asp
George.

"marek" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@phx.gbl...
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
-----Original Message-----
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.

"marek" <ma***@wp.pl> wrote in message
news:01****************************@phx.gbl...
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

>-----Original Message-----
>..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.
>
>"marek" <ma***@wp.pl> wrote in message
>news:0d****************************@phx.gbl...
>> 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
>>
>
>
>.
>

.

Nov 18 '05 #6

P: n/a
Thanks ...

and in addition I was advised this one

http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/dv_vstechart/html/vcconMixedDLLLoadingProblem.asp
merry christmas to all
Marek
-----Original Message-----
May be this article will help.

http://msdn.microsoft.com/library/default.asp? url=/library/en-
us/vcmex/html/vcconconvertingmanagedextensionsforcprojectsf
rompureintermediatelanguagetomixedmode.asp

George.

"marek" <an*******@discussions.microsoft.com> wrote in messagenews:04****************************@phx.gbl...
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
>-----Original Message-----
>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.
>
>
>
>"marek" <ma***@wp.pl> wrote in message
>news:01****************************@phx.gbl...
>> 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
>>
>> >-----Original Message-----
>> >..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.
>> >
>> >"marek" <ma***@wp.pl> wrote in message
>> >news:0d****************************@phx.gbl...
>> >> 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
>> >>
>> >
>> >
>> >.
>> >
>
>
>.
>

.

Nov 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.