Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need a simple FLL
Message
From
19/09/2006 11:51:03
 
General information
Forum:
Visual FoxPro
Category:
Troubleshooting
Miscellaneous
Thread ID:
01154766
Message ID:
01155132
Views:
20
This message has been marked as the solution to the initial question of the thread.
Hi,

this C code will do it:
// include FoxPro LCK header file
#include "pro_ext.h"

void _fastcall StringToHexEx(ParamBlk *parm)
{
	unsigned char *pString, *pHexString;
	unsigned char cHexChar;
	Value vHexString;
        vHexString.ev_type = 'C';

	// compute length of resulting hex string
	vHexString.ev_length = parm->p[0].val.ev_length * 3;
	
	// if len is equal to 0, return an empty string
	if (vHexString.ev_length == 0)
	{
		_RetVal(&vHexString);
		return;
	}

	// allocate a memory buffer for the hex string
	vHexString.ev_handle = _AllocHand(vHexString.ev_length);
	 // raise Error "Insufficient memory" if allocation failed
	if (!vHexString.ev_handle)
		_Error(182);
	
	// lock memory handles and get real pointers
	_HLock(vHexString.ev_handle);
	pHexString = (unsigned char*)_HandToPtr(vHexString.ev_handle);
	_HLock(parm->p[0].val.ev_handle);
	pString = (unsigned char*)_HandToPtr(parm->p[0].val.ev_handle);

	// transform the string to hexadecimal
	for (unsigned int xj = 1; xj <= parm->p[0].val.ev_length; xj++)
	{
		*pHexString++ = '%';
		// upper 4 bits (divide by 16)
		cHexChar = *pString / 16 + '0';
		if (cHexChar > '9')
			cHexChar += 0x7;
                *pHexString++ = cHexChar;
		
		// lower 4 bits (modulo of 16)
		cHexChar = *pString % 16 + '0';
		if (cHexChar > '9')
			cHexChar += 0x7;
               *pHexString++ = cHexChar;

		pString++;
	}
	
	// unlock memory handles and return the hex string
	_HUnLock(parm->p[0].val.ev_handle);
	_HUnLock(vHexString.ev_handle);
	_RetVal(&vHexString);
}


#ifdef __cplusplus
extern "C" {
#endif

FoxInfo FLLFuncs[] = 
{
 {"YourPreferredFoxProFunctionName", (FPFI) StringToHexEx, 1, "C"}
};

FoxTable _FoxTable = {
(FoxTable *)0, sizeof(FLLFuncs)/sizeof(FoxInfo), FLLFuncs
};

#ifdef __cplusplus
}
#endif
have a look @ message #1132393 how to setup a Visual Studio project to compile a FLL.

You may make a small donation @ www.vfp2c.com if you like to pay a little for my efforts.

Christian
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform