DLL dependency question / SetDLLDirectory

前端 未结 4 1462
小鲜肉
小鲜肉 2020-12-20 03:06

I have the following situation and can\'t come up with any good solution.

I have a C++ application (app.exe) installed in C:\\ProgFiles\\MyApp. It needs a bunch of

4条回答
  •  温柔的废话
    2020-12-20 03:45

    one solution to the problem would be use SetDllDirectory function; but, it needs to be first thing you execute on your program (which is hard to do), my solution is to use third party program to set dll directory and then invoke your EXE file as a new process:

    this is third party which will be a EXE file:

    #include 
    
    SetDllDirectory(_T(".dll location"));   
    
    STARTUPINFOW siStartupInfo;
    PROCESS_INFORMATION piProcessInfo;
    memset(&siStartupInfo, 0, sizeof(siStartupInfo));
    memset(&piProcessInfo, 0, sizeof(piProcessInfo));
    siStartupInfo.cb = sizeof(siStartupInfo);
    
    if (CreateProcessW(L".exe location",NULL, NULL, NULL, FALSE,
        0, NULL, NULL,
        &siStartupInfo, &piProcessInfo))
    {
        /* This line waits for the process to finish. */
        /* You can omit it to keep going whilst the other process runs */
        //dwExitCode = WaitForSingleObject(piProcessInfo.hProcess, (SecondsToWait * 1000));
    }
    else
    {
        /* CreateProcess failed */
        //iReturnVal = GetLastError();
    }
    return 0;
    

提交回复
热议问题