Thread: DLLs, Resources and You

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    9

    DLLs, Resources and You

    Hi,

    Im not sure which forum to posts this in, but seems ageneral compiler/settings type of error no one seemingly can answer anything about.

    I've got a dll project that modifies a native unmanaged c++ application/win64 console.
    Now it works fine, and changes it's things, mods stuff to my liking.

    However one day i decided to add a menu to mod and control some of my custom stuff.

    What i did was in my dll findwindow, create a menu and appendmenu.
    I then made a asm hook to DefWindowProc in the application/program, to handle and control messages.

    This works fine.

    The problem comes when i click an option in my menu, that opens a dialogbox using a resource i've created.

    None of my resources seemingly get loaded into the application from the dll.
    Neither my ico files or the box itself.

    And i'n very confused.


    I've done the same things to an earlier version of the Program, altho there i used a hex asm hook to use loadlibrary, so it would load my dll.


    My question is:
    Would LoadLibrary load all resources as well, whereas standard declspec import not load it, when attaching dll to import table?

    Or am i dong something screwy in VS c++ settings ?

    Ill share code if needed, just at work atm.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    It should be obvious you need to load the dll into your application's memory space... Hense LoadLibrary which doesn't need to be asm or anything else... just call the function from your main program.

    DLL Injection is not the easiest or smartest way to do things... DLLs are intended to be application extensions, loaded by the main program, with functions and resourses used by the main program.

    Dynamic-Link Libraries (Windows)

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    9
    Quote Originally Posted by CommonTater View Post
    It should be obvious you need to load the dll into your application's memory space... Hense LoadLibrary which doesn't need to be asm or anything else... just call the function from your main program.

    DLL Injection is not the easiest or smartest way to do things... DLLs are intended to be application extensions, loaded by the main program, with functions and resourses used by the main program.

    Dynamic-Link Libraries (Windows)
    Clearly when i say, i'm injecting then that's probably my only option.
    No offence, but sending me links to what DLL's are won't help me or learn me anything.


    I need to know wether normal _declspec importing via ImportTables Names imports your resources in a DLL file
    -
    contra writing pure machinecode into the application making it use loadlibrary to load itself into the Application makes a difference Resources Wise.

    Not trying to be a smartass, but no one seemingly knows how Windows works in this way, and you saying how to do things optimally ain't helping.


    And if, Loadlib imports resources and a simple import table doesn't - anything i can do without having to force a loadlib written directly into the application?

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    No offence, but sending me links to what DLL's are won't help me or learn me anything.
    Obviously.

    (A hint: I'm betting that microsoft didn't do all the work designing the DLL interface just so you could ignore it.)

  5. #5
    Registered User
    Join Date
    Jul 2011
    Posts
    9
    Quote Originally Posted by CommonTater View Post
    Obviously.

    (A hint: I'm betting that microsoft didn't do all the work designing the DLL interface just so you could ignore it.)
    Fair enough, if you don't know the direct answer.

    But searching thru MSDN(It's big as you know) for details on something, i'm not sure how the hell to classify in the first place would hopefully be my last resort option.


    Was hoping for an actual point from someone where to look or even if i was lucky, a link to the documentation specificly regarding my issue with resources being imported in one injection and not in the next.
    Last edited by MrMac; 07-25-2011 at 06:00 AM.

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    I don't have a specific answer because you have not asked a specific question...

    Really... a little more detail on what you're trying to do might help.

  7. #7
    Registered User
    Join Date
    Jul 2011
    Posts
    9
    I'm importing my dll into another application (No, it's not my application, i have to inject).

    I do this defining _declspec(import/exportdll) in my dll.

    I then use a PE Editor - to write my dll into the ImportTable of the program.



    One thing i just added to my dll, is Create a new Menu.

    CreateMenu/InsertMenu/AppendMenu.


    Among that are some resources for a DialogBox.
    When trying to call these resources with MAKEINTRESOURCE, it fails and they don't seem to exist.
    (Ive also checked, that my IDS arent' conflicting with the original programs resources).

    I've previously done the same to earlier version of this Application.
    However my inject method was different.

    I hardcoded ASM into the application and made it "LoadLibrary" my dll.


    I'm wondering if there's a difference in these injection methods.
    And if dllimport only imports functions and not Resources.

    If so, is there a simple workaround instead of having to manually Load each resource at runtime/init/postload from my dll itself?
    Last edited by MrMac; 07-25-2011 at 06:24 AM.

  8. #8
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    <psychic_debugging>
    You're calling the resource functions wrong. The hModule parameter needs to be the handle for your dll, not NULL.
    </psychic_debugging>

  9. #9
    Registered User
    Join Date
    Jul 2011
    Posts
    9
    Quote Originally Posted by adeyblue View Post
    <psychic_debugging>
    You're calling the resource functions wrong. The hModule parameter needs to be the handle for your dll, not NULL.
    </psychic_debugging>
    <psychic_failing>
    Fail 40.

    Can't remember, will check this when i get home.
    But could quite possibly be that, now that i think about it.
    </psychic_failing>

    If anything else pops up, please let me know.

  10. #10
    Registered User
    Join Date
    Jul 2011
    Posts
    9
    Quote Originally Posted by MrMac View Post
    <psychic_failing>
    Fail 40.

    Can't remember, will check this when i get home.
    But could quite possibly be that, now that i think about it.
    </psychic_failing>

    If anything else pops up, please let me know.
    Turns out this is not it.

    I save the hModule from DLLMain for later use, specificly for this.

    Any other ideas ? GetLastError points to no resource finding as people have geussed.


    Any other things to check? do people want the code itself?

  11. #11
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by MrMac View Post
    Any other things to check? do people want the code itself?
    Yep. In fact you probably should have posted your code in the first message...

  12. #12
    Registered User
    Join Date
    Jul 2011
    Posts
    9
    Quote Originally Posted by CommonTater View Post
    Yep. In fact you probably should have posted your code in the first message...
    Code For DLL Injection Extra Menu | Copy Paste Code

    CLog is a native function of the original program, i've declared.
    It allows for logging on the console.


    My problem is the MAKEINTRESOURCE seems to fail.

    I dunno if pasting Resource will help?

    IDM_EXTMENU_ABOUT can be any value unused.


    gModule is declared as static HMODULE gModule; in the global header of the dll.

  13. #13
    Registered User
    Join Date
    Jul 2011
    Posts
    9
    Quote Originally Posted by MrMac View Post
    Code For DLL Injection Extra Menu | Copy Paste Code

    CLog is a native function of the original program, i've declared.
    It allows for logging on the console.


    My problem is the MAKEINTRESOURCE seems to fail.

    I dunno if pasting Resource will help?

    IDM_EXTMENU_ABOUT can be any value unused.


    gModule is declared as static HMODULE gModule; in the global header of the dll.
    Well, i just saw my error.

    Knew it was Error 40.


    I shall learn to declare better next time.

  14. #14
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by MrMac View Post
    Code For DLL Injection Extra Menu | Copy Paste Code

    CLog is a native function of the original program, i've declared.
    It allows for logging on the console.


    My problem is the MAKEINTRESOURCE seems to fail.

    I dunno if pasting Resource will help?

    IDM_EXTMENU_ABOUT can be any value unused.


    gModule is declared as static HMODULE gModule; in the global header of the dll.
    When you're not working from a header file you have no symbolic names to fuss with... you need to use actual resource names.

    Thus...
    Code:
    // resources
    
    SERVERS DIALOGEX DISCARDABLE 6, 18, 252, 110
    STYLE DS_SHELLFONT|WS_POPUP|DS_MODALFRAME|DS_3DLOOK|DS_NOFAILCREATE|DS_NOIDLEMSG|WS_CAPTION|WS_VISIBLE
    EXSTYLE WS_EX_CONTROLPARENT
    CAPTION "RMRemote : Server Setup"
    FONT 8, "MS Shell Dlg", 0, 0, 1
    {
      CONTROL "", 4000, "ComboBox", WS_BORDER|CBS_SIMPLE|CBS_SORT|CBS_HASSTRINGS|CBS_NOINTEGRALHEIGHT|WS_VSCROLL|WS_TABSTOP, 8, 14, 72, 71
      CONTROL "", 4001, "Edit", ES_CENTER|ES_NUMBER|ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 147, 18, 31, 13
      CONTROL "", 4002, "Edit", ES_AUTOHSCROLL|ES_PASSWORD|WS_BORDER|WS_TABSTOP, 147, 35, 84, 13
      CONTROL "", 4003, "Edit", ES_CENTER|ES_NUMBER|ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 147, 52, 23, 13
      CONTROL "", 4004, "Edit", ES_CENTER|ES_NUMBER|ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 147, 69, 23, 13
      CONTROL "Delete", 4005, "Button", BS_FLAT|WS_TABSTOP, 4, 93, 45, 12
      CONTROL "Defaults", 4006, "Button", BS_FLAT|WS_TABSTOP, 53, 93, 45, 12
      CONTROL "Help", 4100, "Button", BS_FLAT|WS_TABSTOP, 106, 93, 45, 12
      CONTROL "Save", 4101, "Button", BS_FLAT|WS_TABSTOP, 155, 93, 45, 12
      CONTROL "Close", 4102, "Button", BS_FLAT|WS_TABSTOP, 204, 93, 45, 12
      CONTROL " Servers ", 4200, "Button", BS_GROUPBOX, 3, 3, 81, 86
      CONTROL " Server Settings ", 4201, "Button", BS_GROUPBOX, 88, 3, 160, 86
      CONTROL "Port number:", 4202, "Static", SS_CENTERIMAGE|WS_GROUP, 103, 18, 40, 13
      CONTROL "(1000 - 60000)", 4208, "Static", SS_CENTERIMAGE|WS_GROUP, 182, 18, 58, 13
      CONTROL "Password:", 4203, "Static", SS_CENTERIMAGE|WS_GROUP, 103, 35, 40, 13
      CONTROL "Retries:", 4204, "Static", SS_CENTERIMAGE|WS_GROUP, 103, 52, 40, 13
      CONTROL "(0 - 100)", 4205, "Static", SS_CENTERIMAGE|WS_GROUP, 176, 52, 33, 13
      CONTROL "Timeout:", 4206, "Static", SS_CENTERIMAGE|WS_GROUP, 103, 69, 40, 13
      CONTROL "(1 - 60 seconds)", 4207, "Static", SS_CENTERIMAGE|WS_GROUP, 176, 69, 63, 13
    }
    
    
    // C Code...
        hServer = CreateDialog(PgmInst,L"SERVERS",Parent,&ServerTosser);
    (Taken from live code, so I know it works.)

    Also note there are no symbolic names for the controls... in your switch use the control number (4000, 4001, etc in the example) directly.

    Next time please post your code HERE.

  15. #15
    Registered User
    Join Date
    Jul 2011
    Posts
    9
    Quote Originally Posted by CommonTater View Post
    When you're not working from a header file you have no symbolic names to fuss with... you need to use actual resource names.

    Thus...
    Code:
    // resources
    
    SERVERS DIALOGEX DISCARDABLE 6, 18, 252, 110
    STYLE DS_SHELLFONT|WS_POPUP|DS_MODALFRAME|DS_3DLOOK|DS_NOFAILCREATE|DS_NOIDLEMSG|WS_CAPTION|WS_VISIBLE
    EXSTYLE WS_EX_CONTROLPARENT
    CAPTION "RMRemote : Server Setup"
    FONT 8, "MS Shell Dlg", 0, 0, 1
    {
      CONTROL "", 4000, "ComboBox", WS_BORDER|CBS_SIMPLE|CBS_SORT|CBS_HASSTRINGS|CBS_NOINTEGRALHEIGHT|WS_VSCROLL|WS_TABSTOP, 8, 14, 72, 71
      CONTROL "", 4001, "Edit", ES_CENTER|ES_NUMBER|ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 147, 18, 31, 13
      CONTROL "", 4002, "Edit", ES_AUTOHSCROLL|ES_PASSWORD|WS_BORDER|WS_TABSTOP, 147, 35, 84, 13
      CONTROL "", 4003, "Edit", ES_CENTER|ES_NUMBER|ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 147, 52, 23, 13
      CONTROL "", 4004, "Edit", ES_CENTER|ES_NUMBER|ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 147, 69, 23, 13
      CONTROL "Delete", 4005, "Button", BS_FLAT|WS_TABSTOP, 4, 93, 45, 12
      CONTROL "Defaults", 4006, "Button", BS_FLAT|WS_TABSTOP, 53, 93, 45, 12
      CONTROL "Help", 4100, "Button", BS_FLAT|WS_TABSTOP, 106, 93, 45, 12
      CONTROL "Save", 4101, "Button", BS_FLAT|WS_TABSTOP, 155, 93, 45, 12
      CONTROL "Close", 4102, "Button", BS_FLAT|WS_TABSTOP, 204, 93, 45, 12
      CONTROL " Servers ", 4200, "Button", BS_GROUPBOX, 3, 3, 81, 86
      CONTROL " Server Settings ", 4201, "Button", BS_GROUPBOX, 88, 3, 160, 86
      CONTROL "Port number:", 4202, "Static", SS_CENTERIMAGE|WS_GROUP, 103, 18, 40, 13
      CONTROL "(1000 - 60000)", 4208, "Static", SS_CENTERIMAGE|WS_GROUP, 182, 18, 58, 13
      CONTROL "Password:", 4203, "Static", SS_CENTERIMAGE|WS_GROUP, 103, 35, 40, 13
      CONTROL "Retries:", 4204, "Static", SS_CENTERIMAGE|WS_GROUP, 103, 52, 40, 13
      CONTROL "(0 - 100)", 4205, "Static", SS_CENTERIMAGE|WS_GROUP, 176, 52, 33, 13
      CONTROL "Timeout:", 4206, "Static", SS_CENTERIMAGE|WS_GROUP, 103, 69, 40, 13
      CONTROL "(1 - 60 seconds)", 4207, "Static", SS_CENTERIMAGE|WS_GROUP, 176, 69, 63, 13
    }
    
    
    // C Code...
        hServer = CreateDialog(PgmInst,L"SERVERS",Parent,&ServerTosser);
    (Taken from live code, so I know it works.)

    Also note there are no symbolic names for the controls... in your switch use the control number (4000, 4001, etc in the example) directly.

    Next time please post your code HERE.
    I will post, thank you.

    However the linking of names was never the problem.
    The Static declaration of a hmodule object was.

    Can't later then decide to add new data to it, now can i?


    Figured out by using a "dirty fix" GetDllModuleHandle at CExMenu loading and trying to use my fixed base address of my dll as an argument for hmodule in DialogBoxParam..
    Both suprisingly worked - hence the dumb declaration error was the issue.

    Hence a semi issue as andy said, i was actually using NULL, the original programs hmodule, instead of my own.
    Just didn't know it.
    Last edited by MrMac; 07-27-2011 at 03:02 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dlls in C help
    By MushroomWobbit in forum C Programming
    Replies: 1
    Last Post: 01-12-2010, 03:10 AM
  2. .dlls
    By alpha2018 in forum C++ Programming
    Replies: 2
    Last Post: 08-25-2004, 12:27 PM
  3. mfc DLLs
    By fizisyen in forum C++ Programming
    Replies: 5
    Last Post: 02-21-2003, 08:59 PM
  4. Resources, icon, resources....
    By bluehead in forum Windows Programming
    Replies: 11
    Last Post: 05-26-2002, 05:59 AM
  5. using dlls
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 03-22-2002, 07:16 PM