Thanks Vadym for responding,
Even with the /clr switch they are compiled on a function by function basis.
So is it possible to use something like (psydo code):
#prama unmanaged
int CheckDotNETFrameworkExists()
{
if ( ! //check dot net framework exists here )
{
MessageBox(0, "test", "test", MB_OK);
return 1;
}
}
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
if ( CheckDotNETFrameworkExists() )
exit(1);
return ManagedMainFunction(...);
}
#prama unmanaged
int ManagedMainFunction(...)
{
// main function
}
I have not been able to get it to not crash without the .net framework so
far though.
Thanks,
Chris
> Hello, Chris!
>
[quoted text clipped - 31 lines]
> C> Thanks,
> C> Chris
Chris - 03 Dec 2007 23:08 GMT
To elaborate,
When do the managed assemblies get loaded? If I can call unmanaged code
before hand I would be able to check it then.
Thanks,
Chris
> Thanks Vadym for responding,
>
[quoted text clipped - 71 lines]
> > C> Thanks,
> > C> Chris
Michael Nemtsev [MVP] - 04 Dec 2007 06:53 GMT
Hello Chris,
why not to check the registry entries for .NET existence?
it's installed into specific hives and can be easily tracked
---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour
"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
C> To elaborate,
C> When do the managed assemblies get loaded? If I can call unmanaged
C> code before hand I would be able to check it then.
Prashant - 04 Dec 2007 09:25 GMT
As Michael already mentioned, please refer to the below link on registry key
detail
http://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;315291
> Hello Chris,
>
[quoted text clipped - 12 lines]
> C> When do the managed assemblies get loaded? If I can call unmanaged
> C> code before hand I would be able to check it then.
Chris - 04 Dec 2007 14:13 GMT
Thanks for the responses,
Checking if the registry values exist is not a problem, going back to the
original question, the problem is needing to check from a managed project. I
was told that I cannot add any new assemblies to our installation so I need
to know if it is even possible to do. Can I call unmanaged code in a managed
project in a way that the managed code is not loaded until after I check the
registry with unmanaged code? Therefore, the executable will not crash before
the check allowing me to show a dialog if the .net framework does not exist.
Thanks,
Chris
> As Michael already mentioned, please refer to the below link on registry key
> detail
[quoted text clipped - 16 lines]
> > C> When do the managed assemblies get loaded? If I can call unmanaged
> > C> code before hand I would be able to check it then.
Prashant - 05 Dec 2007 12:04 GMT
If you have managed executable this is how it works.The operating system
loader checks for managed modules by examining a bit in the common object
file format (COFF) header. The bit being set denotes a managed module. If the
loader detects managed modules, it loads mscoree.dll, and _CorValidateImage
and _CorImageUnloading notify the loader when the managed module images are
loaded and unloaded.
You won't be able to turn off/on the bit in COFF header by running the
managed executable. Its not possible to run Managed Executable without CLR
which in turn need .net assemblies
But you could probably write an executable in unmanaged code to check for
.net framework and display a dialog box if it doesn't exist and if it does
exists you could launch your managed executable from your unmanaged code and
terminate the unmanaged exe.Managed exe will impersonate the calling process
security access token.
If your application is being deployed you could also make use of the
installation script to warn users.
> Thanks for the responses,
>
[quoted text clipped - 29 lines]
> > > C> When do the managed assemblies get loaded? If I can call unmanaged
> > > C> code before hand I would be able to check it then.
Chris - 06 Dec 2007 20:38 GMT
I am already checking it in the installation script but apparently too many
people decide to uninstall the .net framework at some point. I will probably
just launch my app from an unmanaged exe like you suggested.
Thanks for the help,
Chris
> If you have managed executable this is how it works.The operating system
> loader checks for managed modules by examining a bit in the common object
[quoted text clipped - 48 lines]
> > > > C> When do the managed assemblies get loaded? If I can call unmanaged
> > > > C> code before hand I would be able to check it then.