I'm working in Visual Studio 2017. In my current solution, I have 2 active projects. The 2nd project depends on the 1st project and my 2nd project is my startup application. When I run or compile my 2nd project, there is already a compiled executable of my 1st project that is within my solutions directory...
Here is the directory hierarchy of my solutions - projects:
"SolutionName/Project1/"
- This contains the source code for Project1
"SolutionName/Project2/"
- This contains the source code for Project2
"SolutionName/x64/"
- This contains the x64 versions:
"SolutionName/x64/Debug"
- This contains the x64 debug builds and executables
"SolutionName/x64/Release"
- This contains the x64 release builds and executables
When I run the application with the 2nd project as my startup... The code compiles and runs fine, however, it doesn't appear to be executing the executable from the 1st project...
Here is my main.cpp
#include <Windows.h>
#include <exception>
#include <stdio.h>
#include <tchar.h>
#include <cstdint>
#include <iostream>
uint32_t runProgram(LPCSTR lpApplicationName) {
STARTUPINFOA si;
PROCESS_INFORMATION pi;
// Set the size of the structures
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
// Run the program
CreateProcessA(
lpApplicationName, // the path
NULL, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
CREATE_NEW_CONSOLE, // Opens file in seperate console
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi // Pointer to PROCESS_INFORMATION structure
);
uint32_t cache_size = 0;
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return cache_size;
}
int main() {
try {
const uint32_t cache_size = runProgram("CacheQuery.exe");
std::cout << cache_size << '\n';
}
catch (const std::exception& e) {
std::cerr << e.what() << "\n\n";
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
If I build my solution in Debug mode, both executables are in the same directory for Debug and if I build my solution in Release mode, again both release versions of my executables are in the same directory...
I am getting an output of 0
in the console so I know that runProgram()
is being called and returning, but I'm expecting another console to be opened with the displayed results from the invoked program with its own console handle from its own process. However, I'm not seeing it being invoked or called. CacheQuery.exe
which is my 1st project and it doesn't seem to be executed...
I'm a bit new to this part of the Windows API, so I'm not sure if I'm doing this correctly... I need for my second project to call and run the 1st project... This is part 1 of my question. Once I get this resolved and know that project 2 is calling and executing project 1, then I'll ask my next question about how to retrieve the value that the called executable returns upon exit...