Launching Applications Within a Program

I have a C++ program that processes some text and then sends it as an email attachment using a VB program. The VB program accepts one argument, the filename of the attachment, and returns a value based on if it was successfully sent or not. I have been using system("emailProgram.exe attachmentFileName.txt") to do this and it works. The problem is that it opens up a cmd.exe window while the email program is running. I don't like that.

I have looked into using CreateProcess() but I need the calling application to wait and receive the return value of the email program. Is there a function that fits my needs?

OR if anyone has some good C++ code to send an email with a gmail account that would be even better. I've found a lot of c++ code but none that seems to work for me.
Last edited on
Use CreateProcess(). It will provide a thread handle and a process handle. You can wait for the program to finish by calling WaitForSingleObject() (or one of the other Wait functions) to wait until the process is completed. Then use that same process handle + GetExitCodeProcess() to retrieve the return code from the VB program.
If you want to use your gmail SMTP server use libcurl library directly (download win32 binaries or compile from sources with SSL support, this is required).

Using CreateProcess you can launch an external process with a hidden console window too.
I ended up using libcurl. It was a real exercise using a third party library for the first time. I had to download openSSL and do a lot of Googling to get everything working, but I definitely prefer using one language for the whole package.
Topic archived. No new replies allowed.