|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
why Assembly.LoadFrom() function does'nt load VC++ Project exe fileHello all
I am facing one problem while loading VC++ EXe file through Assembly.LoadFrom() Function, It gives Error - The format of the file 'totest.exe'(VC++) is invalid please give me solution for it LoadFrom is for managed assemblies only. Unmanaged DLL's and EXE's cannot be
loaded by this function. Willy. Show quoteHide quote "Tarandeep Singh" <tarand***@abosoftware.com> wrote in message news:%23nnbuXbxFHA.2848@TK2MSFTNGP15.phx.gbl... > Hello all > I am facing one problem while loading VC++ EXe file through > Assembly.LoadFrom() Function, > It gives Error - > The format of the file 'totest.exe'(VC++) is invalid > please give me solution for it > > Dear Willy,
"Assembly::LoadFrom(<managed C++ assembly>.exe)" does not work if the .Net assemblies (EXE, DLL) is created with managed C++. There comes an exception with the following error message: "Unverifiable image 'DotNetCPPAppl2.exe' can not be run." "LoadFrom" works if the assembly is created with e.g. C# or VB but it is not working for managed C++ assemblies. My environment: .Net Framework 1.1 Visual Studio 2003 Managed C++ .Net Project/Application 2 Sample application using "LoadFrom": One ceated with C# One created with managed C++ Any help would to find a solution for this problem would be great. Regards, Werner Schaudin Schaudin.com, Germany "Willy Denoyette [MVP]" schrieb: Show quoteHide quote > LoadFrom is for managed assemblies only. Unmanaged DLL's and EXE's cannot be > loaded by this function. > > Willy. > > "Tarandeep Singh" <tarand***@abosoftware.com> wrote in message > news:%23nnbuXbxFHA.2848@TK2MSFTNGP15.phx.gbl... > > Hello all > > I am facing one problem while loading VC++ EXe file through > > Assembly.LoadFrom() Function, > > It gives Error - > > The format of the file 'totest.exe'(VC++) is invalid > > please give me solution for it > > > > > > > I think the error message says it all: the assembly built with (managed
extensions for) C++ is unverifiable. The question is, how do you build a verifiable .exe assembly using C++ (whether or not you want to use LoadFrom()). If someone has the answer, I too would be truly grateful. Cheers, Allan Show quoteHide quote "Werner Schaudin" wrote: > Dear Willy, > > "Assembly::LoadFrom(<managed C++ assembly>.exe)" > does not work if the .Net assemblies (EXE, DLL) is created with managed C++. > > There comes an exception with the following error message: > "Unverifiable image 'DotNetCPPAppl2.exe' can not be run." Allan BB wrote:
> I think the error message says it all: the assembly built with If you use VS2005 its easy, use /clr:pure <g>> (managed extensions for) C++ is unverifiable. The question is, how do > you build a verifiable .exe assembly using C++ (whether or not you > want to use LoadFrom()). If someone has the answer, I too would be > truly grateful. If you use VS2003, you have to jump through hoops, and it won't necessarily work. First, you have to get rid of the CRT (and hence no global variables), next you have to get rid of all unmanaged types. Replace static_cast<>'s and reinterpret_cast<>'s. The odd thing is that you have to define a global variable called _fltused and a global function called _check_commonlanguageruntime_version. You also have to compile with /clr:initialAppDomain, which is odd, because this is the v1.0 behaviour (and has problems). Finally, you have to run SetILOnly on the assembly. The full details are here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmex/html/vclrfproducingverifiablecomponentswithmanagedc.asp Richard "Richard Grimes" wrote: Thanks for the (too) speedy reply Richard. I've just posted a more detailed > If you use VS2005 its easy, use /clr:pure <g> > > If you use VS2003, you have to jump through hoops, .... > The full details are here: > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmex/html/vclrfproducingverifiablecomponentswithmanagedc.asp > query on the subject (specifically: why doesn't it work for exe's?), before seeing your reply here. Allan Hello,
any changes to the build is no help for me because we handle with EXE files not created from us. We want to load EXE files from other so software vendors. We do not have the code -- only the EXE file. I still think to know why a managed C++ assembly cannot be loaded with "LoadFrom": The reason is a C++ managed EXE is loaded (using "LoadFrom") to a fixed address (start entry point) into the memory. Because this address is already used by the calling (running) program (my program which calles "LoadFrom") the C++ EXE module is not loaded. A mangaged C++ DLL can be loaded because a DLL does not have a fixed loading address. Werner Schaudin www.schaudin.com "Allan BB" schrieb: Show quoteHide quote > "Richard Grimes" wrote: > > If you use VS2005 its easy, use /clr:pure <g> > > > > If you use VS2003, you have to jump through hoops, > ... > > The full details are here: > > > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmex/html/vclrfproducingverifiablecomponentswithmanagedc.asp > > > > Thanks for the (too) speedy reply Richard. I've just posted a more detailed > query on the subject (specifically: why doesn't it work for exe's?), before > seeing your reply here. > > Allan >
Other interesting topics
.NET Framework Ignores Regional Settings on WinXP
HOW to solve ... System.Net.WebException: Connection closed Not all images are loaded correctly Manifest Resources: format Resources files programatically how to set the steps involved in enabling the ASP. How does FileSystemWatcher work? Documents on .NET framework reduce thumbnal size Printer settings |
|||||||||||||||||||||||