I've had a piece of code that I use all the time that is a list of Windows messages and their accompanying strings. The code used to run "If event = #WM_PAINT : m$+"WM_PAINT" : EndIf and it would return m$. This would, of course, not work with current versions of PB and Tailbite. I switched to including the file and calling it that way for several months, but I got tired of that. So I changed the code to work as a compiled library the same as it did before. This is what I did:
Code: Select all
Global *strptr
ProcedureDLL.i EventStr(event)
If Not *strptr
*strptr = AllocateMemory(255)
EndIf
RtlZeroMemory_(*strptr, 255)
*ptr = *strptr
CopyMemoryString("",@*ptr)
If event = #DM_SPECVERSION
CopyMemoryString("#DM_SPECVERSION ")
EndIf : If event = #DM_ORIENTATION
[...]
ProcedureReturn *strptr
EndProcedure
And because this returns a pointer, I made the following compiled .res to go with it:
Code: Select all
Macro EventName(ev)
PeekS ( EventStr(ev) )
EndMacro
So now when I type "Debug EventName(15)" I get "WM_PAINT" for output, just as I like it.
My question:
Is this the easiest way to overcome the string problem? Is there something simpler or better?