Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
M

mike montagne

@mike montagne
About
Posts
198
Topics
15
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Can we add a textbox & button to a listview
    M mike montagne

    Evidently, Uwe believes your question pertains to adding the textbox and button to a subcomponent. My interpretation of your question is that you want to add a textbox and button to an exterior region. To do so, you would probably want to derive a root or base layer from Control or UserControl, and add your ListView, TextBox and Button to that.

    C#

  • Getting an IntPtr handle to an instance of the executable file that contains a resource.
    M mike montagne

    This is just one permutation of what I tried with GetExecutingAssembly( ). If what you're intimating is that I need to try Assembly.GetManifestResourceStream() to retrieve the bitmaps so they can be assigned to my properties, I'll have to explore that later (?). I'm late to hit the road, but thanks so much for trying to set me straight on this. I'll get around to it as soon as I can.

    C# graphics hardware tutorial question learning

  • Getting an IntPtr handle to an instance of the executable file that contains a resource.
    M mike montagne

    Whoa. Jumps out and grabs you when it's in Bold! :-) I guess I need to learn to *read*! I suppose I was so intent on loading and embedded resource I just assumed this was the method (what other method is there?). So this *does* require calling into LoadLibrary to get the hinstance. I'm going to have to look around to see what method to use to retrieve my managed resources, because that's the way I want to do it. I hope that isn't some odd implementation of "FromFile", even as the resources are managed -- maybe so?

    C# graphics hardware tutorial question learning

  • Getting an IntPtr handle to an instance of the executable file that contains a resource.
    M mike montagne

    In other words, we can get so far as acquiring a "ModuleHandle" from GetExecutingAssembly -- but I can do this with GetAssembly as well: Assembly.GetExecutingAssembly( ).GetModule( "APC" ).ModuleHandle; ModuleHandle however is a struct with no field or conversion method which converts to an IntPtr to the instance of the assembly. That's the missing piece: How to get an IntPtr from the assembly, or something else, which identifies the executable containing the resource. GetExecutingAssembly just looks like another course to the same dead end to me, unless we can get that IntPtr somehow. But thanks for the try! m

    C# graphics hardware tutorial question learning

  • Getting an IntPtr handle to an instance of the executable file that contains a resource.
    M mike montagne

    No, I tried it:

    Glyph1.GMap = Bitmap.FromResource( ( IntPtr )Assembly.GetExecutingAssembly( ), s );
    

    FromResource requires an IntPtr. As I indicated in my question, I need an IntPtr to the executable containing the resource. According to documentation, what you need to do to get *that* assembly is:

                   Type t = this.GetType( );
                   Assembly a = Assembly.GetAssembly( t );
    

    This gets the assembly. The problem is, getting an IntPtr hinstance pointing to the assembly from the assembly. Are you saying that you can get an IntPtr from your calls, because I don't see that in your answer?

    C# graphics hardware tutorial question learning

  • how to get the current version's assembly number`
    M mike montagne

    Thanks, Martin, but the problem here is the approach is not CLS compliant. We need to be able to do this with managed code. It's "as if" Microsoft left out a vital bridge so that, as we are obstructed from a managed solution, we are forced to write Microsoft-dependent approaches.

    C# announcement tutorial

  • Getting an IntPtr handle to an instance of the executable file that contains a resource.
    M mike montagne

    No, my resource is managed. I've added many bitmaps to my class library DLL by the visual process, Project.Add... Existing file... Determining whether it is a managed resource is not the problem. The DLL is loaded by a test application, using the classes as they would typically be deployed. The problem is for the class, when it is in the test application (exe), to assign the bitmap resources to property, preferably with the Bitmap.FromResource( IntPtr hinstance, String bitmapName ) method.

    C# graphics hardware tutorial question learning

  • Getting an IntPtr handle to an instance of the executable file that contains a resource.
    M mike montagne

    In other words, you can't do this, and there doesn't seem to be a way to cast or otherwise derive the IntPtr value so that you could do the equivalent of this:

    Glyph1.GMap = Bitmap.FromResource( ( IntPtr )Assembly.GetAssembly( t ), s );
    

    So the question remains, How do you get an IntPtr to an executable containing a resource?

    C# graphics hardware tutorial question learning

  • Getting an IntPtr handle to an instance of the executable file that contains a resource.
    M mike montagne

    No, my call to Assembly.GetAssembly( t ) gets the assembly. That isn't the problem. The problem is getting an IntPtr handle to the assembly. Any ideas on that? Since I can identify the proper assembly with Assembly.GetAssembly( t ), and since my call to IntPtr h = Process.GetCurrentProcess( ).Handle does not (?) appear to be returning a valid IntPtr to the executable containing the resource (my assembly returned by GetAssembly( t)), I am hoping there is somehow a way to get the IntPtr from my GetAssembly( t ) result. That seems straightforward, but perhaps another way is intended to be the process. In any case, all reasonable suggestions are appreciated. I'm traveling in just a bit, but will return to the forum in a few days.

    C# graphics hardware tutorial question learning

  • Getting an IntPtr handle to an instance of the executable file that contains a resource.
    M mike montagne

    THANKS, MIKE. I gotta run... but I'll give this a go!

    C# graphics hardware tutorial question learning

  • Getting an IntPtr handle to an instance of the executable file that contains a resource.
    M mike montagne

    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.

    C# graphics hardware tutorial question learning

  • How to load class file dynamically in C# .Net
    M mike montagne

    I think you may have a conceptual problem. The assembly loads the class whenever you have an instance of the class or call into the class. At that time, you can reflect the class; but if you wrote the class you should be able to indicate anything about it by even more straightforward processes. Nonetheless, you don't load the file to reflect on the object: You reflect (usually) an instance of the object or a type object representing the class.

    C# csharp tutorial question

  • Building Complicated Objects in an N-tier application...
    M mike montagne

    It is difficult to convey how, over the years, you easily perceive the structure your application requires. But it's all by rules/observations. Strive to conceive of the structure you need to build by perceiving where the best place is for each thing it needs to do. In effect, objects or classes design themselves if you let the job dictate the object. In the end, there is no such thing as a "bad" class, simply because the class involves many objects or properties. Neither is there a real metric you should follow -- how big should a class be, or what are too many instance methods or members for instance? The size of the best defined objects is predicated by doing the job the best way it can be done. A lot of your work then is refining classes. You see that you will benefit if you split your large object up into smaller objects; or you see that you accomplish an important goal better by incorporating a further method. Always however, the job dictates class design. Concentrate on doing the job(s) the best they can be done, and you will build the best classes.

    C# database debugging business tutorial question

  • Getting an object location
    M mike montagne

    Good luck!

    C# visual-studio docker

  • c# and icons...
    M mike montagne

    I know I've seen an example of how to draw a rectangle on the desktop in response to mouse drag events, but I can't recall where. It's been a while. You should be able to dig up an example.

    C# csharp help

  • Math.Round() ambiguity problem
    M mike montagne

    You're welcome. This is a basic type-relevant issue. Math cannot be taken for granted, so you probably want to heed Luc's advice if it affects your process.

    C# help

  • how to get the current version's assembly number`
    M mike montagne

    In other words, the following approach does identify the assembly I need to identify, but I run into a dead end trying to get an IntPtr handle from the "ModuleHandle" struct:

                   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?
    

    Do you know of a way to get the IntPtr value that will return the resources we need to find with Bitmap.FromResource()?

    C# announcement tutorial

  • how to get the current version's assembly number`
    M mike montagne

    Nice to find an expert on an important function. y any chance, do you know if the following snippet is how to get the hinstance we should pass to Bitmap.FromResource()?

                   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( ) + "." );
                        }
    

    Documentation indicates that hinstance is supposed to be "A handle to an instance of the executable file that contains the resource." The snippet is part of a method of a class belonging to a .DLL to which the resource(s) have been added by the visual Project.Properties... Add existing file... process. When this code fails, the FCL message only indicates that "the" (a) parameter is not valid. The resources ostensibly exist. I assume the handle value is the most probable candidate for the problem, unless there is some problem with the registration of the resources which I am not aware of. Much thanks, m

    C# announcement tutorial

  • c# and icons...
    M mike montagne

    I could be wrong, but I don't think there's a practical way to do that. The Task Bar reads the icon from the executable -- you don't have an obvious opportunity to pass an alternate icon to system processes managing the Task Bar.

    C# csharp help

  • Can we add a textbox & button to a listview
    M mike montagne

    Sure. You can descend a class from Control, and add a textbox, button, and listview to it.

    C#
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups