Environment variables can only be passed in one direction: from parent to child processes. In your case, you are trying to go the inverse path, which is extremely difficult.
Instead, you can use a return value of your program
int main(int, char**)
{
// ...
return 123; // some error code maybe
}
to easily communicate with the parent process, but this is limited to integers and you might want to respect existing conventions on the meaning of these return values. Another possibility is to let the main program write to the standard output, which can then be parsed within the batch file for further processing.