Je reçois cette erreur:E2010 Types incompatibles, pourquoi?
[DCC Error] JwaStrSafe.pas(2277): E2010 Incompatible types: 'PSTRSAFE_LPWSTR' and 'PSTRSAFE_LPTSTR'
Ce qui suit est la partie pertinente du code à partir JwaStrSafe.pas (de Jedi Api), Je compile avec le symbole UNICODE défini:
type
STRSAFE_LPWSTR = PWIDECHAR;
PSTRSAFE_LPWSTR = ^STRSAFE_LPWSTR;
{$IFDEF UNICODE}
STRSAFE_LPTSTR = STRSAFE_LPWSTR;
PSTRSAFE_LPTSTR = ^STRSAFE_LPTSTR;
{$ELSE}
...
{$ENDIF}
...
//function declaration
function StringCchCopyExW(
{__out_ecount(cchDest)}pszDest : STRSAFE_LPWSTR;
{__in}cchDest : size_t;
{__in}const pszSrc : STRSAFE_LPCWSTR;
{__deref_opt_out_ecount(pcchRemaining^)}ppszDestEnd : PSTRSAFE_LPWSTR;
{__out_opt}pcchRemaining : PSize_t;
{__in}dwFlags : Cardinal) : HRESULT; stdcall; forward; external;
...
//var passed to function
ppszDestEnd : PSTRSAFE_LPTSTR;
...
{$IFDEF UNICODE}
result := StringCchCopyExW(pszDest, cchDest, pszSrc, ppszDestEnd, pcchRemaining, dwFlags);
{$ELSE}
result := StringCchCopyExA(pszDest, cchDest, pszSrc, ppszDestEnd, pcchRemaining, dwFlags);
{$ENDIF}
Je reçois l'erreur sur l'appel de StringCchCopyExW, sur le paramètre ppszDestEnd. En regardant la définition de type je comprends que PSTRSAFE_LPTSTR est un type de pointeur à STRSAFE_LPTSTR qui est juste un alias de STRSAFE_LPWSTR, pourquoi PSTRSAFE_LPTSTR et PSTRSAFE_LPWSTR sont-ils incompatibles?
Solution
Merci à l'explication de David I remplacé
PSTRSAFE_LPTSTR = ^STRSAFE_LPTSTR;
avec
PSTRSAFE_LPTSTR = PSTRSAFE_LPWSTR;
maintenant le code compile sans erreur.
Merci
Quelle version de Delphi utilisez-vous? –
Je suis usind Delphi XE2 –