Home > Software engineering >  I can not correctly translate the code from MSDN to Delphi. Section DirectShow Step 6. Add Support f
I can not correctly translate the code from MSDN to Delphi. Section DirectShow Step 6. Add Support f

Time:09-07

Please help me to translate the code. I don't know C well, but I know Delphi syntax well. I want to translate code from MSDN:

Step 6. Add Support for COM.

static WCHAR g_wszName[] = L"My RLE Encoder";
CFactoryTemplate g_Templates[] = 
{
  { 
    g_wszName,
    &CLSID_RLEFilter,
    CRleFilter::CreateInstance,
    NULL,
    NULL
  }
};

and

int g_cTemplates = sizeof(g_Templates) / sizeof(g_Templates[0]);

I realized that the first line is a variable. But when translated, it does not work. Error:

This is a string and you defined it as WCHAR.

Next comes the description of the structure, but I do not know such a form.

The last line is also a variable, but it has a / and two values.

In general, I kind of understood the meaning, but do not understand how to write it.

CodePudding user response:

The code roughly translates to Delphi as follows:

const
  g_wszName: PWideChar = 'My RLE Encoder';
var
  g_Templates: array[0..0] of CFactoryTemplate;
...
g_Templates[0].m_Name := g_wszName;
g_Templates[0].m_ClsID := @CLSID_RLEFilter;
g_Templates[0].m_lpfnNew := @CRleFilter.CreateInstance;
g_Templates[0].m_lpfnInit := nil;
g_Templates[0].m_pAMovieSetup_Filter := nil;

and

var
  g_cTemplates: Integer;
...
//g_cTemplates := SizeOf(g_Templates) div SizeOf(g_Templates[0]);
g_cTemplates := Length(g_Templates);
  • Related