Search code examples
c++dllstrcpy

How to call "StrCpyW" function from "shlwapi.dll"? in C++?


I use Code::Blocks as IDE.

And I should use "libshlwapi.a" library in order to use "StrCpyW" function.

But I want to use that function without the library.

In order to achieve that, I should call "shlwapi.dll".

So, I write my codes like this:

void StrCpyW(PWSTR a_wcResultString, PCWSTR p_cwcSourceString)
{
    typedef PWSTR (*tdStrCpyW)(PWSTR, PCWSTR);

    HMODULE hmShlwapi;

    hmShlwapi = LoadLibraryW(L"shlwapi.dll");

    if(hmShlwapi)
    {
        tdStrCpyW fnStrCpyW = (tdStrCpyW)GetProcAddress(hmShlwapi, "StrCpyW");

        fnStrCpyW(a_wcResultString, p_cwcSourceString);
    }

    FreeLibrary(hmShlwapi);
}

So, what is wrong in my codes?


Solution

  • Just use wcscpy instead so you don't have to load any libraries.