Click here to Skip to main content
15,900,906 members
Home / Discussions / C#
   

C#

 
QuestionProtecting application DLL [c#] Pin
sandeep kumar pundhir16-May-07 10:37
sandeep kumar pundhir16-May-07 10:37 
AnswerRe: Protecting application DLL [c#] Pin
Christian Graus16-May-07 10:39
protectorChristian Graus16-May-07 10:39 
GeneralRe: Protecting application DLL [c#] Pin
Stephen Hewitt16-May-07 15:17
Stephen Hewitt16-May-07 15:17 
GeneralRe: Protecting application DLL [c#] Pin
Christian Graus16-May-07 17:49
protectorChristian Graus16-May-07 17:49 
QuestionAutomatic Proxy Detection Question Pin
matt23lucier16-May-07 10:19
matt23lucier16-May-07 10:19 
QuestionSQl Server express Edition Pin
Agyeman16-May-07 9:13
Agyeman16-May-07 9:13 
AnswerRe: SQl Server express Edition Pin
Alireza Loghmani22-May-07 22:14
Alireza Loghmani22-May-07 22:14 
QuestionGetting an IntPtr handle to an instance of the executable file that contains a resource. Pin
mike montagne16-May-07 7:31
mike montagne16-May-07 7:31 
Does anybody know how to get an IntPtr to the executable that contains a resource?

I am successfully getting the assembly containing the type (which I assume [because it is the assembly to which the resource was added] should contain the resource) by calling Assembly a = Assembly.GetAssembly( t ); but how do you get an IntPtr to the executable that contains the resource (which I assume should be this assembly)? I can get a ModuleHandle structure from the assembly; but there doesn't seem to be a way to get an IntPtr to the executable from the ModuleHandle structure:
Type t = this.GetType( );
Assembly a = Assembly.GetAssembly( t ); // SUCCESSFULLY RETURNS THE RIGHT ASSEMBLY, BUT HOW DO WE GET AN IntPtr HANDLE TO THIS?
ModuleHandle mh = a.GetModule( "APC" ).ModuleHandle; // CAN WE GET AN IntPtr TO THE HINSTANCE SOMEHOW FROM mh?
I can get an IntPtr from Process.GetCurrentProcess( ).Handle, but this handle value does not appear to be valid (if indeed the resource I've added to the .DLL assembly are there, as they otherwise appear to be there). In other words, the IntPtr handle returned by the call into GetCurrentProcess does not appear to identify the assembly to which the resource belongs, whereas the call into Assembly.GetAssembly does identify the assembly I want a handle to, but I haven't found what processes to use to get a handle to *that* assembly from the assembly instance:
String s = "MT_ConfirmREFRESH";
IntPtr h = Process.GetCurrentProcess( ).Handle;

try
     {
     Glyph1.GMap = Bitmap.FromResource( h, s );
     }
catch
     {
     throw new Exception( "Bitmap resource " + s + " not found from process handle " + h.ToString( ) + "." );
     }
Succeeding in this is vital to implementing Bitmap.FromResource( IntPtr hinstance, String bitmapName ). I haven't found any examples that don't call into unsafe/unmanaged code. This means nobody is successfully retrieving bitmap resources embedded into class libraries?

That's a bit hard to believe.
AnswerRe: Getting to an instance of the executable file that contains the resource. Pin
led mike16-May-07 7:39
led mike16-May-07 7:39 
GeneralRe: Getting to an instance of the executable file that contains the resource. Pin
mike montagne16-May-07 7:41
mike montagne16-May-07 7:41 
GeneralNot solved. We need to get a handle to the assembly. Pin
mike montagne16-May-07 8:17
mike montagne16-May-07 8:17 
GeneralSo the question remains, How do you get an IntPtr to an executable containing a resource? Pin
mike montagne16-May-07 8:22
mike montagne16-May-07 8:22 
GeneralRe: So the question remains, How do you get an IntPtr to an executable containing a resource? Pin
led mike16-May-07 8:51
led mike16-May-07 8:51 
GeneralRe: So the question remains, How do you get an IntPtr to an executable containing a resource? Pin
mike montagne16-May-07 9:08
mike montagne16-May-07 9:08 
GeneralRe: So the question remains, How do you get an IntPtr to an executable containing a resource? Pin
led mike16-May-07 9:26
led mike16-May-07 9:26 
GeneralRe: So the question remains, How do you get an IntPtr to an executable containing a resource? Pin
mike montagne16-May-07 9:38
mike montagne16-May-07 9:38 
GeneralRe: So the question remains, How do you get an IntPtr to an executable containing a resource? Pin
led mike16-May-07 9:43
led mike16-May-07 9:43 
GeneralRe: So the question remains, How do you get an IntPtr to an executable containing a resource? Pin
mike montagne16-May-07 9:17
mike montagne16-May-07 9:17 
AnswerRe: Getting an IntPtr handle to an instance of the executable file that contains a resource. Pin
Uwe Keim16-May-07 8:22
sitebuilderUwe Keim16-May-07 8:22 
GeneralRe: Getting an IntPtr handle to an instance of the executable file that contains a resource. Pin
mike montagne16-May-07 8:46
mike montagne16-May-07 8:46 
GeneralRe: Getting an IntPtr handle to an instance of the executable file that contains a resource. Pin
Uwe Keim16-May-07 9:21
sitebuilderUwe Keim16-May-07 9:21 
GeneralRe: Getting an IntPtr handle to an instance of the executable file that contains a resource. Pin
mike montagne16-May-07 9:31
mike montagne16-May-07 9:31 
GeneralRe: Getting an IntPtr handle to an instance of the executable file that contains a resource. Pin
Uwe Keim16-May-07 10:02
sitebuilderUwe Keim16-May-07 10:02 
QuestionUnit testing using VS 2005 Team Testing Pin
jayart16-May-07 6:36
jayart16-May-07 6:36 
AnswerRe: Unit testing using VS 2005 Team Testing Pin
Not Active16-May-07 7:43
mentorNot Active16-May-07 7:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.