using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace TestClass { public partial class Form1 : Form { public Form1() { InitializeComponent(); } // ** I did this from a toolbar, but could go anywhere. ** private void xonclick(object sender, EventArgs e) { //********************************************* myserver.myclass xform = new myserver.myclass(); int prnt = (int) this.Handle; int y = xform.SetParent(prnt); //********************************************* } } }VFP
*This entirely self-contained program will build a COM server * called "myserver.myclass" * It will unregister a prior instance, if any IF PROGRAM() != "MYCLASS" ?"this file MUST BE NAMED 'myclass.prg'" return ENDIF IF FILE("myclass.dll") DECLARE integer DllUnregisterServer IN myclass.dll DllUnregisterServer() CLEAR DLLS ENDIF BUILD PROJECT myserver FROM myclass BUILD DLL myserver from myserver recomp *now test this COM server: *ox = CreateObject("myserver.myclass") && create the server object *ox.mydocmd("USE home(1)+'samples\data\customer'") && use a table *?ox.myeval("RECCOUNT()") && get the record count DEFINE CLASS myclass AS Form OLEPUBLIC FUNCTION SetParent(ParentHWnd AS Long) AS Byte ********************************************* ********************************************* DECLARE INTEGER SetParent IN user32; INTEGER hWndChild, INTEGER hWndNewParent IF SetParent(THIS.HWnd, ParentHWnd) <> 0 THIS.Top = 1 THIS.Left = 1 THIS.Width = 190 THIS.Height = 190 THIS.Visible = .T. RETURN 1 ENDIF RETURN 0 ********************************************* ********************************************* ENDFUNC FUNCTION Error(nError, cMethod, nLine) COMreturnerror(cMethod+' err#='+str(nError,5)+; ' line='+str(nline,6)+' '+message(),_VFP.ServerName) && this line is never executed ENDFUNC ENDDEFINE