Connecting Tech Pros Worldwide Forums | Help | Site Map

How to compile ATL module with CLR

Genady Beryozkin
Guest
 
Posts: n/a
#1: Jun 27 '06
Hi,

I've read the article at
http://msdn2.microsoft.com/en-us/library/ms235211.aspx
about how to compile MFC/ATL code, but I still have one question unanswered:

Should I have the
CComModule _Module;
definition and the
CInitInstance()
code compiled as manages or as unmanaged code?

Thanks for any help,
Genady


Marcus Heege
Guest
 
Posts: n/a
#2: Jun 27 '06

re: How to compile ATL module with CLR


"Genady Beryozkin" <GenadyBeryozkin@discussions.microsoft.com> wrote in
message news:AFCA9669-87D9-487E-923E-7C450C9AAF39@microsoft.com...[color=blue]
> Hi,
>
> I've read the article at
> http://msdn2.microsoft.com/en-us/library/ms235211.aspx
> about how to compile MFC/ATL code, but I still have one question
> unanswered:
>
> Should I have the
> CComModule _Module;
> definition and the
> CInitInstance()
> code compiled as manages or as unmanaged code?
>
> Thanks for any help,
> Genady[/color]

Here are some hints:

1) You should define _Module in a file compiled without /clr.
2) You should make sure that no managed code is executed during the
construction of _Module
3) You should not use #pragma unmanaged
4) You should not compile all your project files with /clr

Hope this helps


Brian Muth
Guest
 
Posts: n/a
#3: Jun 27 '06

re: How to compile ATL module with CLR


I respectfully disagree with Marcus. It looks like you have some old VC6
code. I would upgrade the code to VC8 first before applying the steps as
outlined in the KB article.

Brian


Marcus Heege
Guest
 
Posts: n/a
#4: Jun 27 '06

re: How to compile ATL module with CLR


"Brian Muth" <bmuth@mvps.org> wrote in message
news:epPTPthmGHA.3600@TK2MSFTNGP02.phx.gbl...[color=blue]
>I respectfully disagree with Marcus. It looks like you have some old VC6
>code. I would upgrade the code to VC8 first before applying the steps as
>outlined in the KB article.
>
> Brian[/color]

Hi Brian,

maybe I am too jetlagged currently, but VC6 does not support /clr, so the
code must at least have been ported from VC6 to a higher VS version already.
Given that the question refers to an article of the VC8 documentation, I
assume it has been ported to VC8 already. However, I agree with you that if
the project is ported to VC7 or VC7.1, it should first be ported to VC8.

Respectfully, Marcus


Marcus Heege
Guest
 
Posts: n/a
#5: Jun 27 '06

re: How to compile ATL module with CLR


Hi Genady,

Please tell us something more about your question, especially what version
of Visual C++ you are using.

This allows us to give you a more precise answer.

Thanks

"Genady Beryozkin" <GenadyBeryozkin@discussions.microsoft.com> wrote in
message news:AFCA9669-87D9-487E-923E-7C450C9AAF39@microsoft.com...[color=blue]
> Hi,
>
> I've read the article at
> http://msdn2.microsoft.com/en-us/library/ms235211.aspx
> about how to compile MFC/ATL code, but I still have one question
> unanswered:
>
> Should I have the
> CComModule _Module;
> definition and the
> CInitInstance()
> code compiled as manages or as unmanaged code?
>
> Thanks for any help,
> Genady
>[/color]


Brian Muth
Guest
 
Posts: n/a
#6: Jun 28 '06

re: How to compile ATL module with CLR


The OP talks about using _Module, which is part of ATL3 in VS6. VC8 uses
_AtlModule.

Brian.


Marcus Heege
Guest
 
Posts: n/a
#7: Jun 28 '06

re: How to compile ATL module with CLR


Hi Brian,

"Brian Muth" <bmuth@mvps.org> wrote in message
news:%230HDRYkmGHA.4164@TK2MSFTNGP03.phx.gbl...[color=blue]
> The OP talks about using _Module, which is part of ATL3 in VS6. VC8 uses
> _AtlModule.
>
> Brian.[/color]

But VC8 still supports _Module and CComModule, so if the project is ported
from VC6 to VC8, it will likely use the old alternatives...

The only one who can tell us what the concrete situation is, is the original
poster, but it seems he doesn't care about us any more :-)

Marcus


Brian Muth
Guest
 
Posts: n/a
#8: Jun 28 '06

re: How to compile ATL module with CLR


:-)

B


Genady Beryozkin
Guest
 
Posts: n/a
#9: Jun 29 '06

re: How to compile ATL module with CLR


Hi guys,

Thanks for your answers and I certainly do care (I took a day off yesterday,
and there is a time difference).
The code was originally written in VC6, later ported to VC7.1 and then to VC8.
We didn't change much of it, because it just worked.

Now we're considering the use of .Net in some of our modules, which raises
the question of how do we initialize the module properly.

I did try to compile the file that has _Module definition without /clr, but
I get an assertion in a call to "new CDynLinkLibrary(AFX_EXTENSION_MODULE
.....)";
The AFX_EXTENSION_MODULE constant is defined in the same file, and therefore
is should be initialized as unmanaged.

Now I'm not a COM/ATL expert, so I hope to hear your advice on how to make
the /clr introduction most smoothly.

Specifically - should the new CDynLinkLibrary(...) call be made from managed
or unmanaged code?
What about InitInstance()/ExitInstance() methods?

Thanks again for your help,
Genady

"Marcus Heege" wrote:
[color=blue]
> Hi Genady,
>
> Please tell us something more about your question, especially what version
> of Visual C++ you are using.
>
> This allows us to give you a more precise answer.
>
> Thanks
>
> "Genady Beryozkin" <GenadyBeryozkin@discussions.microsoft.com> wrote in
> message news:AFCA9669-87D9-487E-923E-7C450C9AAF39@microsoft.com...[color=green]
> > Hi,
> >
> > I've read the article at
> > http://msdn2.microsoft.com/en-us/library/ms235211.aspx
> > about how to compile MFC/ATL code, but I still have one question
> > unanswered:
> >
> > Should I have the
> > CComModule _Module;
> > definition and the
> > CInitInstance()
> > code compiled as manages or as unmanaged code?
> >
> > Thanks for any help,
> > Genady
> >[/color]
>
>
>[/color]
Marcus Heege
Guest
 
Posts: n/a
#10: Jun 29 '06

re: How to compile ATL module with CLR


Can you reproduce the behavior in a simple project, created from a VC6
wizard, and ported to VS 2005?

I currently do not have VC6 available.

Another question: What files do you compile to native code and what files to
managed code.

Marcus


"Genady Beryozkin" <GenadyBeryozkin@discussions.microsoft.com> wrote in
message news:E47BF404-90BD-45CC-8788-C27E08B866A9@microsoft.com...[color=blue]
> Hi guys,
>
> Thanks for your answers and I certainly do care (I took a day off
> yesterday,
> and there is a time difference).
> The code was originally written in VC6, later ported to VC7.1 and then to
> VC8.
> We didn't change much of it, because it just worked.
>
> Now we're considering the use of .Net in some of our modules, which raises
> the question of how do we initialize the module properly.
>
> I did try to compile the file that has _Module definition without /clr,
> but
> I get an assertion in a call to "new CDynLinkLibrary(AFX_EXTENSION_MODULE
> ....)";
> The AFX_EXTENSION_MODULE constant is defined in the same file, and
> therefore
> is should be initialized as unmanaged.
>
> Now I'm not a COM/ATL expert, so I hope to hear your advice on how to make
> the /clr introduction most smoothly.
>
> Specifically - should the new CDynLinkLibrary(...) call be made from
> managed
> or unmanaged code?
> What about InitInstance()/ExitInstance() methods?
>
> Thanks again for your help,
> Genady
>
> "Marcus Heege" wrote:
>[color=green]
>> Hi Genady,
>>
>> Please tell us something more about your question, especially what
>> version
>> of Visual C++ you are using.
>>
>> This allows us to give you a more precise answer.
>>
>> Thanks
>>
>> "Genady Beryozkin" <GenadyBeryozkin@discussions.microsoft.com> wrote in
>> message news:AFCA9669-87D9-487E-923E-7C450C9AAF39@microsoft.com...[color=darkred]
>> > Hi,
>> >
>> > I've read the article at
>> > http://msdn2.microsoft.com/en-us/library/ms235211.aspx
>> > about how to compile MFC/ATL code, but I still have one question
>> > unanswered:
>> >
>> > Should I have the
>> > CComModule _Module;
>> > definition and the
>> > CInitInstance()
>> > code compiled as manages or as unmanaged code?
>> >
>> > Thanks for any help,
>> > Genady
>> >[/color]
>>
>>
>>[/color][/color]


Genady Beryozkin
Guest
 
Posts: n/a
#11: Jun 29 '06

re: How to compile ATL module with CLR


I'm afraid I can't reproduce it right now, since I also don't have VC6
installed.
Can you point me to instructions of upgrading ATL/MFC code to VC8? (is it
somewhere in MSDN?)

Following the instructions that I found on MSDN, I only compile stdafx.cpp
without /clr and the rest of the files are compiled with /clr. Of course
I escape the dll initialization functions with an #pragma unmanaged section.

I now got it work with few of our dlls (many other dlls remain native),
making the InitInstance() methods to compile as managed code. The
application starts fine, but I get problems at shutdown. Yet, I'm still not
sure whether what I did is right or just works by chance.
I'm not in the office right now (will be back only next week) so I can't
tell exactly was the error message is, but it is some kind of assertion in
the VC's own MFC/ATL code.

Thanks again,
Genady

"Marcus Heege" wrote:
[color=blue]
> Can you reproduce the behavior in a simple project, created from a VC6
> wizard, and ported to VS 2005?
>
> I currently do not have VC6 available.
>
> Another question: What files do you compile to native code and what files to
> managed code.
>
> Marcus
>
>
> "Genady Beryozkin" <GenadyBeryozkin@discussions.microsoft.com> wrote in
> message news:E47BF404-90BD-45CC-8788-C27E08B866A9@microsoft.com...[color=green]
> > Hi guys,
> >
> > Thanks for your answers and I certainly do care (I took a day off
> > yesterday,
> > and there is a time difference).
> > The code was originally written in VC6, later ported to VC7.1 and then to
> > VC8.
> > We didn't change much of it, because it just worked.
> >
> > Now we're considering the use of .Net in some of our modules, which raises
> > the question of how do we initialize the module properly.
> >
> > I did try to compile the file that has _Module definition without /clr,
> > but
> > I get an assertion in a call to "new CDynLinkLibrary(AFX_EXTENSION_MODULE
> > ....)";
> > The AFX_EXTENSION_MODULE constant is defined in the same file, and
> > therefore
> > is should be initialized as unmanaged.
> >
> > Now I'm not a COM/ATL expert, so I hope to hear your advice on how to make
> > the /clr introduction most smoothly.
> >
> > Specifically - should the new CDynLinkLibrary(...) call be made from
> > managed
> > or unmanaged code?
> > What about InitInstance()/ExitInstance() methods?
> >
> > Thanks again for your help,
> > Genady
> >
> > "Marcus Heege" wrote:
> >[color=darkred]
> >> Hi Genady,
> >>
> >> Please tell us something more about your question, especially what
> >> version
> >> of Visual C++ you are using.
> >>
> >> This allows us to give you a more precise answer.
> >>
> >> Thanks
> >>
> >> "Genady Beryozkin" <GenadyBeryozkin@discussions.microsoft.com> wrote in
> >> message news:AFCA9669-87D9-487E-923E-7C450C9AAF39@microsoft.com...
> >> > Hi,
> >> >
> >> > I've read the article at
> >> > http://msdn2.microsoft.com/en-us/library/ms235211.aspx
> >> > about how to compile MFC/ATL code, but I still have one question
> >> > unanswered:
> >> >
> >> > Should I have the
> >> > CComModule _Module;
> >> > definition and the
> >> > CInitInstance()
> >> > code compiled as manages or as unmanaged code?
> >> >
> >> > Thanks for any help,
> >> > Genady
> >> >
> >>
> >>
> >>[/color][/color]
>
>
>[/color]
Marcus Heege
Guest
 
Posts: n/a
#12: Jun 30 '06

re: How to compile ATL module with CLR


"Genady Beryozkin" <GenadyBeryozkin@discussions.microsoft.com> wrote in
message news:681EB440-1CA2-4535-8159-02A87EE476B1@microsoft.com...
[color=blue]
> I escape the dll initialization functions with an #pragma unmanaged
> section.[/color]

Don't use #pragma unmanaged - functions that should be compiled to native
code should end up in files compiled without /clr
[color=blue]
> I now got it work with few of our dlls (many other dlls remain native),
> making the InitInstance() methods to compile as managed code. The
> application starts fine, but I get problems at shutdown.[/color]

Restart the whole VC8 -> VC8 with /clr process again. Do not compile any
existing file with /clr. Add a new emptry file compiled with /clr. Even
though it is empty it ensures that the linker creates a mixed code assembly.
Test this assembly regarding startup and shutdown issues. Add managed code
in the new file.
[color=blue]
> Yet, I'm still not
> sure whether what I did is right or just works by chance.
> I'm not in the office right now (will be back only next week) so I can't
> tell exactly was the error message is, but it is some kind of assertion in
> the VC's own MFC/ATL code.[/color]

Please send me the callstack you see when the assertion occurs. I would like
to use it for research purposes.
[color=blue]
> Thanks again,
> Genady
>
> "Marcus Heege" wrote:
>[color=green]
>> Can you reproduce the behavior in a simple project, created from a VC6
>> wizard, and ported to VS 2005?
>>
>> I currently do not have VC6 available.
>>
>> Another question: What files do you compile to native code and what files
>> to
>> managed code.
>>
>> Marcus
>>
>>
>> "Genady Beryozkin" <GenadyBeryozkin@discussions.microsoft.com> wrote in
>> message news:E47BF404-90BD-45CC-8788-C27E08B866A9@microsoft.com...[color=darkred]
>> > Hi guys,
>> >
>> > Thanks for your answers and I certainly do care (I took a day off
>> > yesterday,
>> > and there is a time difference).
>> > The code was originally written in VC6, later ported to VC7.1 and then
>> > to
>> > VC8.
>> > We didn't change much of it, because it just worked.
>> >
>> > Now we're considering the use of .Net in some of our modules, which
>> > raises
>> > the question of how do we initialize the module properly.
>> >
>> > I did try to compile the file that has _Module definition without /clr,
>> > but
>> > I get an assertion in a call to "new
>> > CDynLinkLibrary(AFX_EXTENSION_MODULE
>> > ....)";
>> > The AFX_EXTENSION_MODULE constant is defined in the same file, and
>> > therefore
>> > is should be initialized as unmanaged.
>> >
>> > Now I'm not a COM/ATL expert, so I hope to hear your advice on how to
>> > make
>> > the /clr introduction most smoothly.
>> >
>> > Specifically - should the new CDynLinkLibrary(...) call be made from
>> > managed
>> > or unmanaged code?
>> > What about InitInstance()/ExitInstance() methods?
>> >
>> > Thanks again for your help,
>> > Genady
>> >
>> > "Marcus Heege" wrote:
>> >
>> >> Hi Genady,
>> >>
>> >> Please tell us something more about your question, especially what
>> >> version
>> >> of Visual C++ you are using.
>> >>
>> >> This allows us to give you a more precise answer.
>> >>
>> >> Thanks
>> >>
>> >> "Genady Beryozkin" <GenadyBeryozkin@discussions.microsoft.com> wrote
>> >> in
>> >> message news:AFCA9669-87D9-487E-923E-7C450C9AAF39@microsoft.com...
>> >> > Hi,
>> >> >
>> >> > I've read the article at
>> >> > http://msdn2.microsoft.com/en-us/library/ms235211.aspx
>> >> > about how to compile MFC/ATL code, but I still have one question
>> >> > unanswered:
>> >> >
>> >> > Should I have the
>> >> > CComModule _Module;
>> >> > definition and the
>> >> > CInitInstance()
>> >> > code compiled as manages or as unmanaged code?
>> >> >
>> >> > Thanks for any help,
>> >> > Genady[/color][/color][/color]


Bruno van Dooren
Guest
 
Posts: n/a
#13: Jun 30 '06

re: How to compile ATL module with CLR


>> I escape the dll initialization functions with an #pragma unmanaged[color=blue][color=green]
>> section.[/color]
>
> Don't use #pragma unmanaged - functions that should be compiled to native
> code should end up in files compiled without /clr[/color]

Hi Marcus,

You seem to be very adamant about not using #pragma unmanaged.
is there a specific reason, or side effects that are not obvious?
The only thing I can see against it would be readability and practical
problems with project maintenance.

kind regards,
Bruno.



Marcus Heege
Guest
 
Posts: n/a
#14: Jul 3 '06

re: How to compile ATL module with CLR


"Bruno van Dooren" <bruno_nos_pam_van_dooren@hotmail.comwrote in message
news:OMxTlCCnGHA.1248@TK2MSFTNGP05.phx.gbl...
Quote:
Quote:
Quote:
>>I escape the dll initialization functions with an #pragma unmanaged
>>section.
>>
>Don't use #pragma unmanaged - functions that should be compiled to native
>code should end up in files compiled without /clr
>
Hi Marcus,
>
You seem to be very adamant about not using #pragma unmanaged.
is there a specific reason, or side effects that are not obvious?
The only thing I can see against it would be readability and practical
problems with project maintenance.
>
kind regards,
Bruno.
http://www.heege.net/blog/default.as...9-9da8ec9e091e


Closed Thread


Similar .NET Framework bytes