#include <string.h>
#include <windows.h>
#include "revstr.h"
/* dll initiator function */
int CALLBACK DllMain (HANDLE hInstance, DWORD fdwReason, PVOID pvReserved)
{
return (TRUE) ; /* all ok, continue */
}
/* The BlockRev() function reverses the order of the bytes in a */
/* global memory block. The bytes are copied temporarily into */
/* the hgMem block, and then copied back into the input block. */
/* Returns TRUE if all OK, FALSE on error. */
BOOL CALLBACK BlockRev (HANDLE hgInput, int nLong)
{
int i ;
HANDLE hgMem ;
LPSTR lpSource, lpDest, lps, lpd ;
/* allocate temporary buffer, length + 1 for terminal null */
hgMem = GlobalAlloc (GMEM_MOVEABLE | GMEM_DISCARDABLE,
(LONG) (nLong + 1)) ;
if (hgMem)
{
lpDest = (LPSTR)GlobalLock (hgMem) ; /* lock both blocks */
lpSource = (LPSTR)GlobalLock (hgInput) ;
lpd = lpDest ; /* points to start of dest */
lps = lpSource + nLong - 1 ; /* points to end of source */
for (i = 0 ; i < nLong ; i++) /* reverse copy to dest */
*lpd++ = *lps-- ;
for (i = 0 ; i < nLong ; i++) /* copy back to source */
*lpSource++ = *lpDest++ ;
GlobalUnlock (hgInput) ; /* leave input unlocked */
GlobalFree (hgMem) ; /* free temp buffer */
return (TRUE) ;
}
return (FALSE) ;
}