user1601401
user1601401

Reputation: 732

get string from dll c++

I use eclipse and mingw compilier (c++). I would like to create a dll file which contains a lot of strings. After that I would like to call with LoadString() to read the string (http://msdn.microsoft.com/en-us/library/windows/desktop/ms647486(v=vs.85).aspx)

my dll file:

#define WIN32_LEAN_AND_MEAN
#define DLL_FUNC extern "C" __declspec(dllexport)

DLL_FUNC int __stdcall Hello() {

    return 0;

 }

my cpp file:

#include <windows.h>
#include <stdio.h>

    int main () {

    typedef int (__stdcall *HelloProc)();

        HMODULE hdll = LoadLibrary("HelloWorld.dll");
        if( hdll == NULL){
            MessageBox(HWND_DESKTOP, "Wrong dll path", "Message", MB_OK);
        }
        else {
            typedef int (__stdcall *HelloProc)();

            HelloProc Hello = (HelloProc)GetProcAddress(hdll, "Hello@0");
            if(Hello == NULL){
                //LoadString();
                MessageBox(HWND_DESKTOP, "Hello is NULL", "Message", MB_OK);
            }
            else{
                Hello();
            }
        }

        return 0;
    }

How do I create the strings? And how to call with LoadString()?

Upvotes: 2

Views: 2501

Answers (1)

Steve Valliere
Steve Valliere

Reputation: 1207

I think you want to read about resources so that you can build a resource-only DLL containing a string table. Try searching the MSDN site you referenced for things like resource compiler and maybe how to build a resource only DLL and how to use string tables. I'm sure you will find documentation and examples at Microsoft and, if not, with Google.

Oh, your DLL is not required to be resource only, I got that from your comment "I would like to create a dll file which contains a lot of strings." It is actually even easier (maybe more straightforward) to do if your DLL will also contain code. Then you'd want to search for adding resources to a DLL and things like that.

Upvotes: 3

Related Questions