开发者

Spaces are removed from command line arguments when external dll is called from c#

开发者 https://www.devze.com 2023-02-26 02:30 出处:网络
We\'ve a library written in c which is called by our main application which is written in c# (V 3.5).

We've a library written in c which is called by our main application which is written in c# (V 3.5).

Previous version of our c# application was in Delphi and that one was also using the same library.

The usage mode is as follows:

we load the library using DLLImport in the c# code and call the required function. That function creates a process using a external dll lying in the library folder and passes path of a text file which will be processed by the external dll.

The problem is that when this process was being done through Delphi application, everything was fine. but, now all the spaces are removed from the path of the text file and it is resulting in "file not found" error from the external dll.

Code in the c file:

`Some Work  
  // This routine executes the process  
  if (!Cr开发者_JAVA技巧eateProcess (NULL,                 // No module name (use command line).    
                      ProcessCommandLine, // Command line to execute, format : LibraryFolderPath\ExternalLibrary.exe Text File Path\TextFileName.txt  
                      NULL,               //   
                      NULL,               // Thread handle not inheritable.  
                      FALSE,              // Set handle inheritance to FALSE.  
                      0,                  // No creation flags.  
                      NULL,               // Use parent's environment block.  
                      DirPath,            // Use parent's starting directory.  
                      &StartupInfo,       // Pointer to STARTUPINFO structure.  
                      &ProcessInfo )      // Pointer to PROCESS_INFORMATION structure.  
    )
  {
    // if fails to start application return to caller
    return;
  } // if !CreateProcess 

The path specified as "Text File Path\TextFileName.txt" gets modified as "TextFilePath\TextFileName.txt" for the ExternalLibrary.exe

I've tried quoting the path but that didn't help.

Any specific reason for this behavior or any solution??


From the documentation:

If lpApplicationName is NULL, the first white space–delimited token of the command line specifies the module name. If you are using a long file name that contains a space, use quoted strings to indicate where the file name ends and the arguments begin (see the explanation for the lpApplicationName parameter). If the file name does not contain an extension, .exe is appended. Therefore, if the file name extension is .com, this parameter must include the .com extension. If the file name ends in a period (.) with no extension, or if the file name contains a path, .exe is not appended. If the file name does not contain a directory path, the system searches for the executable file in the following sequence.

I know that you are not working with the above mentioned parameter, but the trick might help.

0

精彩评论

暂无评论...
验证码 换一张
取 消