GetEntryAssembly needed but not there...

  • Thread starter Thread starter Thomas Hansen
  • Start date Start date
T

Thomas Hansen

Hello, I've got this control library (ImageButton) which needs to load
resources from the entry assembly.
Basically I submit a resource string to the ImageButton which in turn
is being used to load a bitmap from the resources of the main exe
assembly...
So I've got this exe file (lets call it a.exe) and this control
library(c.dll) and the c.dll needs to load from the resources of the
a.exe which it can't since I can't get to the assembly??
I've tried GetCallingAssembly and GetExecutingAssembly, but both
returns the assembly of the c.dll!
I suspect it has to do with the point I am invoking the
GetCallingAssembly from, but anyway I desperately need to get to the
"outer most" assembly! (a.exe)

All help seriously appreciated!

..t
 
Not sure why GetCallingAssembly is not working for you but to directly
answer your question, GetEntryAssembly or getting the outermost assembly is
not supported in managed code.

You can try a workaround based on pinvoking GetModuleFileName.

Cheers
Daniel
 
Hi Daniel, and thank you for your quick reply!

Since I don't have the code where I am now I can't recall the exact
layout of my code, but I think to remember that I called it
(Get-Executing/Calling-Assembly) in OnPaint since I had this
"initialize bitmap" function called upon every paint message which
checked if the bitmap was loaded and if not loaded it...
Therefor I guess both the code calling OnPaint and the executing
assembly would be the same...
Anyway, they are the same, I checked up with the Name property and saw
they both were my dll...

To use GetModuleFileName how would I do that?
Can I construct an Assembly from a UintPtr or something?!?
Or would I have to go "completely unmanaged" and do my own Windows API
wrapper around reading resources such as my bitmap...
How would I in such a case create a Managed bitmap from it?!?

..t
 
Ok, so basically I need to load the assembly (which I already have
loaded since it's the exe file) and use that one to load my bitmaps
from the resource of that assembly...
Wouldn't that be a serious memory overhead (especially since I can't
unload it again)?!?

Sounds depressing...
:(

Anyway, thank you!

..t
 
If you can wait for CF 2.0, that will support unloading.

Also:
"Loading an assembly that is already loaded doesn't have any serious cost" -
Brian Smith [MSFT]

Cheers
Daniel
 
I've got a "dirty hack" around it at the present time though...
I've got this static data member which is of type Assembly which I need
to "set" in e.g. "static int Main()"...
Then I can use this static reference to load from the main assembly
though...
It's a bit dirty since it poses "obscure" requirements on users of the
library, but I think it's better then to waste lots of memory in a
library ment for a PPC app...
(all though Brian claims it's not much, I tend to think if it's one
byte it's one too much in PPC)
Seems like I'm gonna be stuck with my hack then for some time...
;)

Thank you alot for all your help!

..t
 
Back
Top