Recent

Author Topic: [Solved] UnicodeString and CreateProcessW  (Read 3643 times)

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1248
[Solved] UnicodeString and CreateProcessW
« on: July 01, 2014, 02:53:52 pm »
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: [Select]
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;   

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)
« Last Edit: July 01, 2014, 03:24:10 pm by Mike.Cornflake »
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: UnicodeString and CreateProcessW
« Reply #1 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.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1248
Re: UnicodeString and CreateProcessW
« Reply #2 on: July 01, 2014, 03:23:56 pm »
well you do need to convert the string to widestring that is done using the utf8decode/utf8encode not the sys variant.
Brilliant.  UTF8Decode was the go...
Many, *many* thanks :)

Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines