Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Call for small C routine
Message
From
21/01/2003 06:26:53
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
20/01/2003 15:35:34
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Miscellaneous
Thread ID:
00743550
Message ID:
00743699
Views:
11
>Hi,
>
>Does anybody here have, or know how to write, a small C or C++ program to receive a call from VFP and pass it to an ActiveX object's method and then provide a return, in order to get around the situation described in the following reference: http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q177575
>
>1) The ActiveX expects several parameters: some are values and some are variants passed by reference;
>2) The code needed is a small routine to act as a go between that will pass things back and forth to get around the known issue in these cases.
>3) It is OK to require a separate procedure to be a front end to each ActiveX routine.
>
>Thank you very much !
>
>Alex

Alex,
Check Message #555095 for FLL creating steps.
If you use winApiMs.lib that comes with VFP7 you'd run into ATLS.Lib not found. It happened only once to me (reruns didn't show). If u have VC7 (.NET) atls.lib is in atl\lib folder.
For your case it sounds it'd be good to work with an object. Below is a sample VFP+C code for object demo (Add_property, Get_Property are C routines):
/*
VFP sample code :
o1 = createobject('Custom')
o2 = createobject('Container')
_screen.addobject('MyShape','Shape')
? Add_Property(o1,"Test_Property1",12345)
? Add_Property(o1,"Test_Property2","Hello")
? Add_Property(o1,"Test_Property3",date())
? Add_Property(_screen.myShape,"bgcolor",0xffff00)
? Add_Property(o2,"objref",createobject('textbox'))
o2.objref.Value = 'MyValue'
luValue1 = Get_Property(o1,"Test_Property1")
luValue2 = Get_Property(o1,"Test_Property2")
luValue3 = Get_Property(o1,"Test_Property3")

? type('luValue1'), luValue1
? type('luValue2'), luValue2
? type('luValue3'), luValue3
with _screen.myShape
	.Top = 100
	.Left = 100
	.BackColor = .bgcolor
	.Visible = .t.
endwith
luObj = Get_Property(o2,"objref")
? luObj.Name, luObj.Baseclass, luObj.Value
set library to
wait window 'Any key to continue...'
_screen.myShape.Visible = .f.
_screen.removeobject('myShape')

*/
#include <pro_ext.h>

char FAR *NullTerminate(Value FAR *cVal)
{
	char *RetVal;
	if (!_SetHandSize(cVal->ev_handle, cVal->ev_length + 1))
	{
		_Error(182); // "Insufficient memory"
	}
	
	((char FAR *) _HandToPtr(cVal->ev_handle))[cVal->ev_length] = '\0';
	RetVal = (char FAR *) _HandToPtr(cVal->ev_handle);
	return RetVal; 
}

void FAR PropGet(ParamBlk FAR *parm)
{
	#define obj (parm->p[0].val)
	#define prpname (parm->p[1].val)

	Value val;
	ZeroMemory(&val, sizeof (Value));

	char FAR *PropertyName = NullTerminate(&prpname);
	int Success = _GetObjectProperty(&val, &obj, PropertyName) ;
	if ( Success != 0)
	{
		_Error(Success*-1);
	}
	else
	{
		_RetVal(&val); 
	}
}

void FAR PropAdd(ParamBlk FAR *parm)
{
	#define obj (parm->p[0].val)
	#define prpname (parm->p[1].val)
	#define prpval (parm->p[2].val)


	char FAR *PropertyName = NullTerminate(&prpname);

	// success code - 0 success, 
        //negative error abs value foxpro error number
        // 1 add if not exists
	int Success = _SetObjectProperty(&obj, PropertyName, &prpval, 1) ; 
	if ( Success != 0)
	{
		_Error(Success*-1);
	}
	else
	{
		_RetLogical(1); // Return .T. to foxpro
	}
}

FoxInfo myFoxInfo[] =
{
	{"Add_Property", (FPFI) PropAdd, 3, "OC?"},
	{"Get_Property", (FPFI) PropGet, 2, "OC"},
};


extern "C" {
FoxTable _FoxTable =
{
	(FoxTable *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};
}
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform