CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Display Strings

  1. #1
    Join Date
    Sep 2009
    Posts
    6

    Display Strings

    I have an EXE file and i want to list all the strings from the String Table of the EXE
    The exe is the compiled CPP file like the one present in the Debug folder
    How do i display all the strings that are present??

  2. #2
    Join Date
    May 2005
    Posts
    4,954

    Re: Display Strings

    Try this article.

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  3. #3
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Display Strings

    Quote Originally Posted by nixter View Post
    I have an EXE file and i want to list all the strings from the String Table of the EXE?
    I already answered you in your previous thread. What was wrong there for you?
    Victor Nijegorodov

  4. #4
    Join Date
    Sep 2009
    Posts
    6

    Re: Display Strings

    I have used this code till now. Is this proper?

    #include "stdafx.h"
    #include "windows.h"
    #include "tchar.h"
    #include "stdio.h"
    #include "string.h"

    BOOL CALLBACK MyStringCB(HMODULE some_library,LPCTSTR RT_String,LPTSTR buffer,LONG_PTR aux_param);

    char buffer[200];

    int _tmain(int argc, _TCHAR* argv[])
    {DWORD S;
    LPCTSTR RT_String=NULL;
    LONG_PTR aux_param=NULL;
    BOOL q,r;
    HMODULE some_library = LoadLibrary("C:/Hi/Debug/Hi.exe");
    q= MyStringCB(some_library,RT_String,buffer,aux_param);
    r=EnumResourceNames(some_library, RT_STRING, MyStringCB, aux_param);

    S=GetLastError();

    return 0;

    }

    BOOL CALLBACK MyStringCB(HMODULE some_library,LPCTSTR RT_String,LPTSTR buffer,LONG_PTR aux_param)
    { DWORD startId = ((DWORD)buffer - 1) * 16;
    DWORD i, endId = startId + 16;
    for (i = startId ; i < endId; ++i)
    { LoadString(some_library, i,buffer,sizeof(buffer));
    }
    return TRUE;
    }

  5. #5
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Display Strings

    Quote Originally Posted by nixter View Post
    I have used this code till now. Is this proper?
    No. Some serious problem are there.
    1. Always use Code tags while posting code snippets. Otherwise your code is almost unreadable.
    2. Don't be so lazy to *no* insert spaces after commas - the same reason as above.
    3. Why are you using obsolete char type instead of TCHAR?
    4. What does this magic number '200' mean? Why not '20' or 2000'?
    5.
    Code:
    LPCTSTR RT_String=NULL;
    Wrong! You may not redefine this value. Otherwise the rest of your code does not make any sense!

    6.
    Code:
    HMODULE some_library = LoadLibrary("C:/Hi/Debug/Hi.exe");
    Wrong! you must use double backslashes!

    7.
    Code:
    r=EnumResourceNames(some_library, RT_STRING, MyStringCB, aux_param);
    
    S=GetLastError();
    Wrong. GetLastError makes any sense only if API call failed. So:
    Code:
    if(!EnumResourceNames(some_library, RT_STRING, MyStringCB, aux_param))
         S=GetLastError();
    8.
    Code:
    q= MyStringCB(some_library,RT_String,buffer,aux_param);
    Wrong! MyStringCB is a callback function and is called by the system from within the EnumResourceNames (or some other) API. You must not call it yourself!

    .......
    Well, did you read the article i referred to?
    Did you try to download the Microfoft code to get/read/update string resources?
    Victor Nijegorodov

  6. #6
    Join Date
    Sep 2009
    Posts
    6

    Re: Display Strings

    We made the changes suggested by you. While debugging the error is that RT_String needs to be initialized.
    Yes i downloaded the STablUpd and am very new to C++ ,just started 2 months back.


    #include "stdafx.h"
    #include "windows.h"
    #include "tchar.h"
    #include "stdio.h"
    #include "string.h"

    BOOL CALLBACK MyStringCB(HMODULE some_library,LPCTSTR RT_String,LPTSTR buffer,LONG_PTR aux_param);

    char buffer[200];

    int _tmain(int argc, _TCHAR* argv[])
    {DWORD S;
    LPCTSTR RT_String;
    LONG_PTR aux_param=NULL;
    BOOL q,r;
    HMODULE some_library = LoadLibrary("C:\\Hi\\Debug\\Hi.exe");

    //q= MyStringCB(some_library,RT_String,buffer,aux_param);
    r=EnumResourceNames(some_library, RT_STRING, MyStringCB, aux_param); //ERROR HERE.
    //MyStringCb is not being called

    if(!EnumResourceNames(some_library, RT_STRING, MyStringCB, aux_param))
    S=GetLastError();

    return 0;

    }

    BOOL CALLBACK MyStringCB(HMODULE some_library,LPCTSTR RT_String,LPTSTR buffer,LONG_PTR aux_param)
    { DWORD startId = ((DWORD)buffer - 1) * 16;
    DWORD i, endId = startId + 16;
    for (i = startId ; i < endId; ++i)
    { LoadString(some_library,i,buffer,sizeof(buffer));

    }

    return TRUE;
    }

  7. #7
    Join Date
    Nov 2007
    Posts
    613

    Re: Display Strings

    The line:
    Code:
    LPCTSTR RT_String;
    is just a declaration of a pointer. You need to create a memory area to hold actual string.

    You should write:
    Code:
    LPCTSTR RT_String = new TCHAR[desired size];
    Don't forget to call the delete operator when you no longer need the string.

  8. #8
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Display Strings

    Quote Originally Posted by nixter View Post
    We made the changes suggested by you. }
    No, you dibn't!
    Once more:

    Quote Originally Posted by VictorN View Post
    No. Some serious problem are there.
    1. Always use Code tags while posting code snippets. Otherwise your code is almost unreadable.
    2. Don't be so lazy to *no* insert spaces after commas - the same reason as above.
    3. Why are you using obsolete char type instead of TCHAR?
    4. What does this magic number '200' mean? Why not '20' or 2000'?
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured