Click here to Skip to main content
15,888,025 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to build a sample Win32 Exe Application in which I am loading msvcr90.dll from C:\ProgramFiles(x86)\ folder. But it is throwing error. My purpose is to load msvcr90.dll from application's path instead of C:\Windows\WinSxS folder. But not able to do so.

What I have tried:

C++
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPTSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    // TODO: Place code here.
    MSG msg;
    HACCEL hAccelTable;

    // Initialize global strings
    LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    LoadString(hInstance, IDC_DEMO_LOAD_EXE, szWindowClass, MAX_LOADSTRING);
    MyRegisterClass(hInstance);

    // Perform application initialization:
    if (!InitInstance (hInstance, nCmdShow))
    {
        return FALSE;
    }

    DWORD dwError = 0;
    SetLastError(dwError);
    LoadLibrary(L"C:\\Program Files (x86)\\<myapp>\\<myapp1>\\msvcr90.dll");
    dwError = GetLastError();


    hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_DEMO_LOAD_EXE));

    // Main message loop:
    while (GetMessage(&msg, NULL, 0, 0))
    {
        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return (int) msg.wParam;
}
Posted
Updated 21-Feb-17 0:47am
v2

Quote:
LoadLibrary(L"C:\\Program Files (x86)\\<myapp>\\<myapp1>\\msvcr90.dll");
dwError = GetLastError();
You are providing an invalid path ('<' and '>' are not allowed in paths).
You are plainly ignoring the GetLastError return value.
 
Share this answer
 
Comments
Member 10019512 21-Feb-17 10:19am    
CPallini, in here <> is referring to my application's path. <myapp> and <myapp1> are not actual values, just the interpretation values. I have copied the path of dll as it is from the location.
Also, in GetLastError, I am getting 126 error value that means module not found.
It would help to know the error code and message.

But I guess that it fails because it has been already loaded from a different location (the system folder).

If you really want to place the runtime DLL in your application folder this may help:
How do i tell application manifest file to use a DLL in current directory ?[^].
Then there is also no need to load the DLL manually.

But there is usually no reason to do so. A better alternative would be linking the runtime statically (Project properties, C/C++, Code Generation, Runtime Library: /MT and /MTd for debug builds).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900