1

I have a C++ application (.Exe) dealing with Images. It takes a picture IN as parameter and automatically saves a new one as output.

I Want to run MY C# application, it will run the .exe one with string parameters and instead of having to read the image on the HDD i would like the C++ application to return right away a string or something to the parent C# app to deal with it again before saving on hdd.

I have the C++ source code. So i can modify its output that is for now:

unsigned char *pixels = new unsigned char[width * height * 3];
unsigned char *p = pixels, *b = bitmap;
int col, row;

for (row = 0; row < height; row++)
for (col = 0; col < width; col++)
{
    *p++ = *b;
    *p++ = *b;
    *p++ = *b++;
}

corona::Image *img = corona::CreateImage(width, height, IMAGE_FORMAT, pixels);
corona::SaveImage(filename, corona::FF_AUTODETECT, img);
delete img;

So, what would be the new code in that C++ app? And what would be the code in my C# main parent app to run and get that output back to deal with? thanks guys

EDIT: For the C# part (Running C++ .exe and grabbing back the Output), i think i found the solution here on StackOverflow : How to hide cmd window while running a batch file?

Still need the C++ part since i totally know nothing about C++ please.

Community
  • 1
  • 1
user3916429
  • 562
  • 6
  • 25

1 Answers1

1

You can do this one of two ways

  1. Create named shared memory in the C# application, pass the name of this shared memory to the C++ application. The C++ application then writes its results to this shared memory, which can be processed by the C# application before being written to the final file.
  2. Write Base64 encoded data from the C++ app to stdout (using printf or cout) and read that in from the parent C# application, decode and process.

Note that option 1 will be much faster than option 2

Ani
  • 10,826
  • 3
  • 27
  • 46
  • Ok this Shared Memory looks like a really great solution, but how can i know the C++ app finished its job and so everything is written on it ,please? Edit: i will have to use that on a loop to process thousands of images. So i really need to know when Memory is free to read and use. – user3916429 Apr 08 '15 at 09:09
  • I guess mixing both your solutions would do the trick! "C# parent app (A)" start the "C++ app (B)", B create and write to shared memory, then output some text eg "done". A read output, when it receive the "done" output, means memory is ready for the use. A reads memory and can do the job again for another image. Please correct me if i am wrong. – user3916429 Apr 08 '15 at 10:38
  • its getting weird. trying to rebuild the C++ gives me a Linker Error LNK1123. Saw a solution here... but i wont reinstall a service pack just for that purpose sadly... So except if someone is cool enought to convert my C++ into C# code. I will just stop the project here, so cant tell if it works or not. sorry. – user3916429 Apr 08 '15 at 13:23
  • To sychronize the C++ and C# code, you can use a named mutex C++: https://msdn.microsoft.com/en-us/library/windows/desktop/ms682411(v=vs.85).aspx, C#: https://msdn.microsoft.com/en-us/library/f55ddskf(v=vs.110).aspx. As for your linker error, have you tried all the solutions listed there? – Ani Apr 08 '15 at 18:18
  • yes i tried all solutions listed. i didn't install vs2012 either so... and i dont want to install a service pack only for some C++ lines. Because i never code in C++ at all. To be honest i have started to translate the C++ code into C#, just having troubles with 7 lines because i simply dont understand what its doing... – user3916429 Apr 08 '15 at 21:44
  • I'd recommend posting a new question here on Stackoverflow for it. – Ani Apr 08 '15 at 21:44
  • ok thank you, i kinda know i will get neg reped for it but i will do it because i really needs it as it is. – user3916429 Apr 08 '15 at 21:47
  • here it is incase... http://stackoverflow.com/questions/29526246/translating-a-c-dealing-with-corona-function-into-c-sharp – user3916429 Apr 08 '15 at 22:13