View Full Version : Delphi: convert a string to WideChar
Sirber
4th September 2005, 18:25
I have a function that use a "pWideChar" field as input. If I feed it manually it work #1, like 'c:\test.avi'. I'm trying to feed it with a string and it fails.
Anyone knows how to do it?
Thanks! :D
Sirber
4th September 2005, 18:29
found it. kidna hard :devil:
var
source: string;
filename: pWideChar;
begin
// Convert filename
GetMem(filename, sizeof(WideChar) * Succ(Length(source)));
StringToWideChar(source, filename, Succ(Length(source)));
ShowMessage(WideCharToString(filename));
FreeMem(filename);
Zyphon
4th September 2005, 22:33
Thanks Sirber this is useful information. :)
Sirber
5th September 2005, 00:33
Usefull if you wanna use MediaInfoLib :D
Zyphon
6th September 2005, 01:48
Usefull if you wanna use MediaInfoLib :D
Yeah thanks for the heads up. :D
Sirber
6th September 2005, 02:18
Are you trying to not say that you are making a software? :eek:
Zyphon
6th September 2005, 09:58
Are you trying to not say that you are making a software? :eek:
No not yet, I am still learning to program with Delphi and information like will no doubt help me if I encounter the same problems that you did. Hopefuly soon when I actually get some time to learn as I am busy at the moment I can start to make some programs.
I would like to as it is a fun hobby to do.
I have been using Delphi 7 to learn with as I was told Delphi 8 and 2005 have a lot of bugs in them although I hear that the 2005 version has several patches to fix this.
What version do you use to program with and do you recommend that I upgrade or stick with what I have got?
Thanks for any advice you can give me. :)
Sirber
6th September 2005, 13:59
I tryed 8 and 2005 and I don't like .NET and 2005 implementation of VCL. Also, most help for delphi avalible on the net is for 7.
Zyphon
6th September 2005, 16:50
Thanks for the advice Sirber, Amnon82 also agreed with you and said via PM that I should stick with version 7, so thanks to both of you for your advice I appreciate it. :)
TFM_TheMask
8th September 2005, 20:32
You also can do this in Delphi 2005 for MediaInfoLib latest beta:
var
FileName : string;
TempFileName : Widestring;
begin
TempFileName := WideString(FileName);
Handle := MediaInfo_New();
IsOpen := MediaInfo_Open(Handle, PWideChar(TempFileName));
..
.....
..
MediaInfo_Delete(Handle);
end;
Sirber
10th September 2005, 18:05
There are no "MediaInfo_New();" with the bundeled Delphi sample. :confused:
var
FileName : string;
TempFileName : Widestring;
begin
TempFileName := WideString(FileName);
Damn. Seems I can remove my "memory copy" and use QideString instead. I so looked for this :(
Sirber
10th September 2005, 18:08
filename := WideString(setting.source);
handle := MediaInfo_Open(filename);
[Erreur] UAnalyze.pas(140): Types incompatibles : 'WideString' et 'PWideChar'
Doesn't work :(
TFM_TheMask
10th September 2005, 20:27
There are no "MediaInfo_New();" with the bundeled Delphi sample. :confused:
Damn. Seems I can remove my "memory copy" and use QideString instead. I so looked for this :(
You are right, the sample is not updated yet, but if you change it to this:
procedure TForm1.FormCreate(Sender: TObject);
var
Handle, IsOpen : Cardinal;
To_Display: WideString;
f : WideString;
f1 : string;
begin
To_Display := MediaInfo_Option (0, 'Info_Version', '');
To_Display := To_Display + '\r\n\r\nInfo_Parameters\r\n\r\n';
To_Display := To_Display + MediaInfo_Option (0, 'Info_Parameters', '');
To_Display := To_Display + '\r\n\r\nInfo_Capacities\r\n';
To_Display := To_Display + MediaInfo_Option (0, 'Info_Capacities', '');
To_Display := To_Display + '\r\n\r\nInfo_Codecs\r\n';
To_Display := To_Display + MediaInfo_Option (0, 'Info_Codecs', '');
To_Display := To_Display + '\r\n\r\nOpen\r\n';
f1 := 'E:\Temp\Mr.and.Mrs.Smith.DVDSCR.CD1.mp4';
f := f1;
Handle := MediaInfo_New();
IsOpen := MediaInfo_Open(Handle, Pwidechar(f));
To_Display := To_Display + '\r\n\r\nInform with Complete=false\r\n';
MediaInfo_Option (0, 'Complete', '');
To_Display := To_Display + MediaInfo_Inform(Handle, 0);
To_Display := To_Display + '\r\n\r\nInform with Complete=true\r\n';
MediaInfo_Option (0, 'Complete', '1');
To_Display := To_Display + MediaInfo_Inform(Handle, 0);
To_Display := To_Display + '\r\n\r\nCustom Inform\r\n';
MediaInfo_Option (0, 'Inform', 'General;Example : FileSize=%FileSize%');
To_Display := To_Display + MediaInfo_Inform(Handle, 1);
To_Display := To_Display + '\r\n\r\nGetI with Stream=General and Parameter:=13\r\n';
showmessage(MediaInfo_GetI(Handle, 0, 0, 13, 1));
To_Display := To_Display + MediaInfo_GetI(Handle, 0, 0, 13, 1);
To_Display := To_Display + '\r\n\r\nCount_Get with StreamKind=Stream_Audio\r\n';
To_Display := To_Display + format('%d', [MediaInfo_Count_Get(Handle, 2, -1)]);
To_Display := To_Display + '\r\n\r\nGet with Stream:=General and Parameter=^AudioCount^\r\n';
To_Display := To_Display + MediaInfo_Get(Handle, 0, 0, 'AudioCount', 1, 0);
To_Display := To_Display + '\r\n\r\nGet with Stream:=Audio and Parameter=^StreamCount^\r\n';
To_Display := To_Display + MediaInfo_Get(Handle, 2, 0, 'StreamCount', 1, 0);
To_Display := To_Display + '\r\n\r\nGet with Stream:=General and Parameter=^FileSize^\r\n';
To_Display := To_Display + MediaInfo_Get(Handle, 0, 0, 'FileSize', 1, 0);
To_Display := To_Display + '\r\n\r\nClose\r\n';
MediaInfo_Delete(Handle);
Memo1.Text := To_Display;
end;
and change the mediainfodll.pas file to:
interface
uses
{$IFDEF WIN32}
Windows;
{$ELSE}
Wintypes, WinProcs;
{$ENDIF}
function MediaInfo_New(): Cardinal cdecl {$IFDEF WIN32} stdcall {$ENDIF};
procedure MediaInfo_Delete(Handle: Cardinal) cdecl {$IFDEF WIN32} stdcall {$ENDIF};
function MediaInfo_Open(Handle: Cardinal; File__: PWideChar): Cardinal cdecl {$IFDEF WIN32} stdcall {$ENDIF};
procedure MediaInfo_Close(Handle: Cardinal) cdecl {$IFDEF WIN32} stdcall {$ENDIF};
function MediaInfo_Inform(Handle: Cardinal;
Options: Integer): PWideChar cdecl {$IFDEF WIN32} stdcall {$ENDIF};
function MediaInfo_GetI(Handle: Cardinal;
StreamKind: Integer;
StreamNumber: Integer;
Parameter: Integer;
KindOfInfo: Integer): PWideChar cdecl {$IFDEF WIN32} stdcall {$ENDIF};
function MediaInfo_Get(Handle: Cardinal;
StreamKind: Integer;
StreamNumber: Integer;
Parameter: PWideChar;
KindOfInfo: Integer;
KindOfSearch: Integer): PWideChar cdecl {$IFDEF WIN32} stdcall {$ENDIF};
function MediaInfo_Option(Handle: Cardinal;
Option: PWideChar;
Value: PWideChar): PWideChar cdecl {$IFDEF WIN32} stdcall {$ENDIF};
function MediaInfo_State_Get(Handle: Cardinal): Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};
function MediaInfo_Count_Get(Handle: Cardinal;
StreamKind: Integer;
StreamNumber: Integer): Integer cdecl {$IFDEF WIN32} stdcall {$ENDIF};
implementation
function MediaInfo_New; external 'MediaInfo.Dll';
procedure MediaInfo_Delete; external 'MediaInfo.Dll';
procedure MediaInfo_Close; external 'MediaInfo.Dll';
function MediaInfo_Open; external 'MediaInfo.Dll';
function MediaInfo_Inform; external 'MediaInfo.Dll';
function MediaInfo_GetI; external 'MediaInfo.Dll';
function MediaInfo_Get; external 'MediaInfo.Dll';
function MediaInfo_Option; external 'MediaInfo.Dll';
function MediaInfo_State_Get; external 'MediaInfo.Dll';
function MediaInfo_Count_Get; external 'MediaInfo.Dll';
end.
TFM_TheMask
10th September 2005, 20:30
filename := WideString(setting.source);
handle := MediaInfo_Open(filename);
[Erreur] UAnalyze.pas(140): Types incompatibles : 'WideString' et 'PWideChar'
Doesn't work :(
Do you use Delphi 2005 ??
Sirber
11th September 2005, 05:37
Nope, good old v7 :D
I don't like .NET stuff on my PC :)
TFM_TheMask
11th September 2005, 09:46
That is why my solution does not work for you, I think it only works on Delphi 2005, sorry. You have to stick with your solution.
Sirber
11th September 2005, 16:29
k, thanks for try! The missing _New could explain why I got access violation with the 0.7 beta.
Zyphon
12th September 2005, 20:21
I don't like .NET stuff on my PC :)Me either, I hate that you have to install the M$ .Net framework to get some VB proggies to work. :(
[Toff]
13th September 2005, 20:10
filename := WideString(setting.source);
handle := MediaInfo_Open(filename);
[Erreur] UAnalyze.pas(140): Types incompatibles : 'WideString' et 'PWideChar'
Doesn't work :(
You forgot to cast the WideString to PWideChar
Anyway this 2 way are equivalent :
var filenameW : WideString;
...
filenameW := setting.source;
// 1st way
handle := MediaInfo_Open(@filenameW[1]);
// 2nd way
handle := MediaInfo_Open(PWideChar(filenameW));
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.