Forum > Windows

[Solved] UnicodeString and CreateProcessW

(1/1)

Mike.Cornflake:
Sorry to keep hammering away at this, I've got a bee in my bonnet :(

I've got CreateProcessW working in a simple test case.  From the reading I've done - UnicodeString would appear to be best fit for this code (but I've tried WideString as well) .

Can anyone shed any light on why this isn't passing a correct encoded string through to mplayer? 


--- Code: ---procedure TForm1.Button2Click(Sender: TObject);
var
  StartInfo: TStartUpInfo;
  ProcInfo: TProcessInformation;
  createOK: Boolean;
  PName,PDir,PCommandLine : PWideChar;
  sName, sDir, sCommandLine : UnicodeString;      //  Also tried WideString here, but I suspect UnicodeString is a better fit...

begin
  FillChar(StartInfo, SizeOf(TStartUpInfo), #0);
  FillChar(ProcInfo, SizeOf(TProcessInformation), #0);
  StartInfo.cb := SizeOf(TStartUpInfo);
  StartInfo.dwFlags      := STARTF_USESHOWWINDOW;
  StartInfo.wShowWindow := SW_SHOWMINIMIZED;

  sName := 'B:\Code\Compile\mplayer-svn-37216\mplayer.exe';
  sDir := 'B:\Code\Compile\mplayer-svn-37216';
 
  sCommandLine := '-vo direct3d "B:\Code\Compile\Test Data\test2.mpg"';  //  This line works
  //sCommandLine := '-vo direct3d "B:\skiing-ǤǥǦ.avi"';                  //  This line doesn't - notice the encoding in the filename

  PName := PWideChar(sName);
  PCommandLine := PWideChar(sCommandLine);
  PDir := PWideChar(sDir);

  createOK := CreateProcessW(PName,PCommandLine,Nil, Nil, false,
                           CREATE_NEW_PROCESS_GROUP+HIGH_PRIORITY_CLASS,
                           NIL, PDir, STARTINFO, PROCINFO);
  if createOK then
    waitForSingleObject(PROCINFO.HPROCESS, Infinite)
  else
    ShowMessage('Create Failed');
end;   
--- End code ---

CreateOK is returning true here.  When I throw in assorted SysToUTF8 or UTF8ToSys, then CreateOK returns false.  Which makes some sort of sense to me.

This is my main reference page
http://wiki.freepascal.org/FPC_Unicode_support

but I've also been bimbling through http://docwiki.embarcadero.com/RADStudio/XE/en/Enabling_Applications_for_Unicode (kind of dangerous I know as fpc and delphi are in different places right now with this stuff)

taazz:
well you do need to convert the string to widestring that is done using the utf8decode/utf8encode not the sys variant.

Mike.Cornflake:

--- Quote from: taazz on July 01, 2014, 02:58:11 pm ---well you do need to convert the string to widestring that is done using the utf8decode/utf8encode not the sys variant.

--- End quote ---
Brilliant.  UTF8Decode was the go...
Many, *many* thanks :)

Navigation

[0] Message Index

Go to full version