我在C++应用程序中创建了一个用户界面,它使用一个C DLL来操纵EXIF文件。这个C dll使用system()函数打开cmd窗口和一个记事本文件进行编辑,当我们关闭记事本文件时,输入的数据被编辑到exif头注释中。现在我必须隐藏这个cmd窗口,我使用了“start\b”,但是这会关闭cmd窗口,这会导致编辑exif头文件,而不会在记事本文件中输入数据。
此函数的代码如下。
FILE * file;
int a;
char QuotedPath[PATH_MAX+10];
file = fopen(TempFileName, "w");
if (file == NULL)
{
fprintf(stderr, "Can't create file '%s'\n",TempFileName);
ErrFatal("could not create temporary file");
}
fwrite(Comment, CommentSize, 1, file);
fclose(file);
fflush(stdout); // So logs are contiguous.
{
char * Editor;
Editor = getenv("EDITOR");
if (Editor == NULL)
{
#ifdef _WIN32
Editor = "notepad";
#else
Editor = "vi";
#endif
}
if (strlen(Editor) > PATH_MAX) ErrFatal("env too long");
sprintf(QuotedPath, "%s \"%s\"",Editor, TempFileName);
a = system(QuotedPath);
}
if (a != 0)
{
char message[50]= "";
strcpy(message, "Editor failed to launch");
MessageBoxA(hWnd,message,"Error : ",MB_ICONWARNING);
// perror("Editor failed to launch");
exit(-1);
}
if (hFileOpen != NULL)
{
file = fopen(TempFileName, "r");
if (file == NULL)
{
ErrFatal("could not open temp file for read");
}
// Read the file back in.
CommentSize = fread(Comment, 1, 999, file);
fclose(file);
unlink(TempFileName);
return CommentSize;
}