synopse / mORMot

Synopse mORMot 1 ORM/SOA/MVC framework - Please upgrade to mORMot 2 !
https://synopse.info
785 stars 323 forks source link

No interpretation for error messages in SynCrtSock.SysErrorMessagePerModule on my machines #411

Closed FeelAirSlow closed 2 years ago

FeelAirSlow commented 2 years ago

Hello,

My system is in french language and when a winhttp.dll error is raised in SynCrtSock, I only have the error code but no textual explanation.

May I suggest a slight modification in SynCrtSock ? The function SysErrorMessagePerModule, could be modified to fall back to the default behaviour (cf. https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-formatmessage) if english langage is not available. Moreover, it may also be useful to use the FORMAT_MESSAGE_IGNORE_INSERTS flag (cf. https://devblogs.microsoft.com/oldnewthing/20071128-00/?p=24353).

  tmpLen := FormatMessage(
    FORMAT_MESSAGE_FROM_HMODULE or FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_IGNORE_INSERTS,
    pointer(GetModuleHandle(ModuleName)),Code,ENGLISH_LANGID,@err,0,nil);
  // if string is empty, it may be because english is not found
  if (tmpLen = 0) then
     tmpLen := FormatMessage(
       FORMAT_MESSAGE_FROM_HMODULE or FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_IGNORE_INSERTS,
       pointer(GetModuleHandle(ModuleName)),Code,0,@err,0,nil);

Thank you !

synopse commented 2 years ago

Should be fixed now.

Note that mORMot 2 already included this fallback in mormot.core.os.windows.inc.

FeelAirSlow commented 2 years ago

I tested your modifications of SynCrtSock.pas : that's perfect, thank you !