Welcome, Guest
Username: Password: Remember me
CodeTyphon MS Windows (Win7, Win8.x, Win10 and Win11) OS Development, discussions and problems
  • Page:
  • 1

TOPIC:

char* to free pascal, change parameters in filter 9 years 2 weeks ago #7021

  • Carmelo
  • Carmelo's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 13
  • Thank you received: 0
hello there. I use CT 5.20 for win7 32bit
I have to convert this, to free pascal CT, to change parameters in a filter directshow, i have a guide written in c. Filters are :
videoprocessing
I use only ScaleFilter.dll for resize my video. In SettingsInterface.h to describe how to configure the filter in application.
DEFINE_GUID( IID_ISettingsInterface, /* 388EEF20-40CC-4752-A0FF-66AA5C4AF8FA */
    0x388eef20, 0x40cc, 0x4752, 0xa0, 0xff, 0x66, 0xaa, 0x5c, 0x4a,
    0xf8, 0xfa);
#undef  INTERFACE
#define INTERFACE   ISettingsInterface

DECLARE_INTERFACE_( ISettingsInterface, IUnknown )
{
    /// Method to set parameter named type to value
    STDMETHOD(SetParameter)( const char* type, const char* value) = 0;
};
my translation
type
  ISettingsInterface = interface(IUnknown)
    ['{388EEF20-40CC-4752-A0FF-66AA5C4AF8FA}']

    function SetParameter(const tipo , valore: LPWStr): HResult; stdcall;
...
const targetwidth  = 'targetwidth';
      targetheight = 'targetheight';
      tipowidth    = '720';
      tipoheight   = '576';
     IID_ISettingsInterface : TGUID = '{388EEF20-40CC-4752-A0FF-66AA5C4AF8FA}'; 
var 
  pSettingsInterface :ISettingsInterface;
...
ScaleFilter.QueryInterface(IID_ISettingsInterface,pSettingsInterface); 
hr := pSettingsInterface.SetParameter(targetwidth, tipowidth);
hr := pSettingsInterface.SetParameter(targetheight,tipoheight); 
fgRender.Play;
in hr := pSettingsInterface.SetParameter .... hr returns ( E_FAIL )
in play i receve error ( External error SIGSEGV );
I think that LPWStr not is correct translation from char*
Someone can help me?

Please Log in or Create an account to join the conversation.

char* to free pascal, change parameters in filter 9 years 2 weeks ago #7027

  • Tony_O_Gallos
  • Tony_O_Gallos's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • Ελεύθερο λογισμικό ή θάνατος
  • Posts: 84
  • Thank you received: 23
Hi carmeloconny,

the parameters you use are using are pointers on strings in order to be compatible with COM interface/stdcall.
You should declare it with PChar (or PAnsiChar or even PWideChar )
As you are using constant strings for your paramters, you have to cast them before the call.

function SetParameter(tipo, valore : PChar): HResult; stdcall;
and then
hr := pSettingsInterface.SetParameter(PChar(targetwidth), PChar(tipowidth));
or
hr := pSettingsInterface.SetParameter(PChar('targetwidth'), PChar('720'));

Hoping this will help you :)

Please Log in or Create an account to join the conversation.

char* to free pascal, change parameters in filter 9 years 2 weeks ago #7029

  • Carmelo
  • Carmelo's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 13
  • Thank you received: 0
thank you for reply.
i tried:
char and pAnsiChar = error run ( External error SIGSEGV ); in hr := pSettingsInterface.SetParameter....
with
pwideChar = in hr := pSettingsInterface.SetParameter.... ( hr result " E_FAIL ") and in run play i receve ( External error SIGSEGV );
in site:
Change Video Resolution speak the same problem for translate in c#. They have solved with LPWStr. Perhaps it can be useful to read

Please Log in or Create an account to join the conversation.

char* to free pascal, change parameters in filter 9 years 1 week ago #7032

  • Tony_O_Gallos
  • Tony_O_Gallos's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • Ελεύθερο λογισμικό ή θάνατος
  • Posts: 84
  • Thank you received: 23
According the link you sent and the one of the interface, it should be a PChar, pointing at a null-terminated (ansi) string.
See PChar - Null terminated strings from the FreePascal documentation for more details...
Don't forget the terminal #0!

Please Log in or Create an account to join the conversation.

char* to free pascal, change parameters in filter 9 years 1 week ago #7041

  • Carmelo
  • Carmelo's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 13
  • Thank you received: 0
Thanks, i solved!

The point is that if an interface has two methods (like in this case get and setparameter), and you only want to call the second (setparameter), you must nevertheless also define the first method (getparameter).

This because in normal interfaces the functions are linked to the external code based on position rather than name.

thanks Marcov.
const IID_ISettingsInterface : TGUID = '{388EEF20-40CC-4752-A0FF-66AA5C4AF8FA}';
type
    ISettingsInterface = interface(IUnknown)
      ['{388EEF20-40CC-4752-A0FF-66AA5C4AF8FA}']
    //  STDMETHOD(GetParameter)( const char* type, int buffersize, char* value, int* length ) = 0;
    function GetParameter(const tipo: LPWStr; buffersize: integer; valore:LPWStr; length : PINT):HRESULT; stdcall;
    //  STDMETHOD(SetParameter)( const char* type, const char* value) = 0;
    function SetParameter(const tipo, valore: PChar): HRESULT; stdcall;
  end;
I have declared GetParameter and SetParameter, ( char* = PCHAR ). I use only SetParameter, now works!
Thank you all.

Please Log in or Create an account to join the conversation.

  • Page:
  • 1