Archive: system plugin with getlasterror and formatmessage


system plugin with getlasterror and formatmessage
  Hi people,

I´m been trying to modify a function on this link (http://nsis.sourceforge.net/Reading_...from_DLL_files) to use formatmessage in conjunction with getlasterror, so I can get the verbose message from kernel32 funcions called with ?e at the end.

My approach is like this:


define FORMAT_MESSAGE_FROM_SYSTEM      0x00001000

>!define FORMAT_MESSAGE_ALLOCATE_BUFFER 0x00000100
>!define FORMAT_MESSAGE_IGNORE_INSERTS 0x00000200
>!define FORMAT_MESSAGE_MAX_WIDTH_MASK 0x000000FF

>!macro ReadStringFromDLL STRING_ID VAR
System::Call 'kernel32::GetSystemDefaultLangID(i v)i .R0'
StrCpy $0 ${FORMAT_MESSAGE_FROM_SYSTEM}
IntOp $0 $0 + ${FORMAT_MESSAGE_ALLOCATE_BUFFER}
IntOp $0 $0 + ${FORMAT_MESSAGE_IGNORE_INSERTS}
IntOp $0 $0 + ${FORMAT_MESSAGE_MAX_WIDTH_MASK}
System::Call 'kernel32::FormatMessage(i r0,i n, i ${STRING_ID}, i R0, *w .R2, i ${NSIS_MAX_STRLEN}, i n) i .R3'
StrCpy ${VAR} $R2
>!macroend
>
the result on ${VAR} is a bunch of '????????????????' that I dont understand where it came from... :stare:

Reading MSDN (http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx), it appears to be right.

Seen a lot of people have problem with this function.

Some help would be much appreciated. ;)

(sorry the bad english)

Use FormatMessageW or change *w to *t maybe...


Got It
 

Anders

Use FormatMessageW or change *w to *t maybe...
Got It! but just changing to *t, FormatMessageW gives only fist char of the message string, I cant find information at MSDN/Google about the especific "FormatMessageW"

Many Thanks, its working now. :D:D:D

Use FormatMessageW or change *w to *t (FormatMessage+*t or FormatMessageW+*w)

There is no FormatMessage, there is only FormatMessageA and FormatMessageW. To use the system plugin you should know a thing or two about the Windows API...