.NETGURU
Calling a .NET assembly through PURE UNMANAGED code
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Nadav (VIP)
Hi,

I am tiring to load an assembly from memory ( e.g.
System.Reflection.Assembly.Load( byte[] ), this works fine through managed
and mixed code. NOW, I am tiring to achieve the same thing through PURE
UNMANAGED code, I can't use com or com interop, does some one have an idea
how to achieve what was just described? ( through unmanaged code )
Is it possible to call a managed assembly through PURE UNMANAGED code? how?
( if at-all )

Again, I can't use COM so COM Interop will not satisfy my needs
--
Nadav
http://www.ddevel.com
Reply to this message...
 
    
Niki Estner
"Nadav" <Click here to reveal e-mail address> wrote in
news:Click here to reveal e-mail address...
[Original message clipped]

Why can't you use COM? AFAIK the .net runtime exposes parts of its native
functionality through COM interfaces.
If COM really isn't an option, there are still a few solutions I can think
of, but I'm not sure you will like them:
- run the manages process using CreateProcess, and communicate with it on
standard IPC channels like pipes or sockets
- Create the managed assembly in MC++, which can create "ordinary" DLL
exports, that can be used with GetProcAddress
- Load the managed DLL with GetProcAddress, and use some windows messaging
code to get in contact with the managed code.

Niki

Reply to this message...
 
    
Nadav (VIP)
Hi Niki,

Thanks for your responce, Well, for me, exposing managed code through
DLLExport or through COM Interop is the same, as long as some code would be
able to be implemented using managed code it would be easy do decompile it or
get it's IL ( the dotfuscator will not solve my problem here ), SOooo a small
piece of my project should be written in unmanaged code ( which if far harder
to de-compile ), this part must include the ...Assembly.Load.....
functionality, If I could use a managed assembly directly from within my
unmanaged code it would solve my problem...

"Niki Estner" wrote:

[Original message clipped]

Reply to this message...
 
    
Niki Estner
"Nadav" <Click here to reveal e-mail address> wrote in
news:Click here to reveal e-mail address...
[Original message clipped]

Is there any reason why you can't use COM in your unmanaged code? (I'm *not*
talking about COM interop!)
If not, have a look at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconhostingcommonlanguageruntime.asp.

Niki

Reply to this message...
 
    
Nadav (VIP)
Thanks, I think that migth help...

"Niki Estner" wrote:

[Original message clipped]

Reply to this message...
 
    
Thomas Scheidegger [MVP] (VIP)
[Original message clipped]

Use the 'Managed Extensions for C++ .NET'.
There you can mix managed & unmanaged code.

Mixing Managed and Unmanaged Classes
http://msdn.microsoft.com/library/en-us/vcmxspec/html/vcManagedExtensionsSpec_16.asp

Wrapper:
http://msdn.microsoft.com/library/en-us/dncscol/html/csharp12192002.asp

--
Thomas Scheidegger - MVP .NET - 'NETMaster'
http://www.cetus-links.org/oo_dotnet.html - http://dnetmaster.net/

Reply to this message...
 
    
Nadav (VIP)
Hi Thomas,

Thanks for your resounce, Indeed you are right, BUT creating a mixed mode
executable causes the IL code to be embedded in the raw EXE file, still, this
managed code is able to be de-compiled ( by ildasm for instance ) and this is
exacly what i am tring to avoid.

P.S.
Writing a managed assembly exposed by Com Interop impose the same problem as
the assembly exposed by COM Interop would be able to be decompiled...

"Thomas Scheidegger [MVP]" wrote:

[Original message clipped]

Reply to this message...
 
    
Thomas Scheidegger [MVP] (VIP)
[Original message clipped]

so 'your problem' is to prevent de-compiling?

Currently, 'managed code' always means IL-code and metadata, by design.
Thus there is no easy solution for you.

My recommendation:
use .NET the way it was designed for.

Maybe there are (IMHO strange) third-party tools
to compile IL code to native code....
But this will NOT be real .NET anymore.

Or maybe a 'hybrid' solution could work for you?
In theory, I don't have tried it:
create a classic Win32 EXE,
'embed' an assembly-file as raw data,
then use the .NET hosting APIs / Interfaces
CorBindToRuntimeEx, ICorRuntimeHost, _AppDomain....
to load & execute this raw data as assembly....
(but needs strong COM knowledge)

--
Thomas Scheidegger - MVP .NET - 'NETMaster'
http://www.cetus-links.org/oo_dotnet.html - http://dnetmaster.net/

Reply to this message...
 
 
System.AppDomain
System.Reflection.Assembly




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification