Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Working with sockets
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Divers
Thread ID:
01339151
Message ID:
01339181
Vues:
30
Hi Mark,

>No, it does not have to be socket communications. I simply did not find another way of feeding .Net process with a small peice of VFP data at a real time.

The code samples I have do it the other way round, sending data from .NET to VFP. But that might get you started, as well. Here's the code in C# that sends a message to the VFP window:
Boolean SendData(IntPtr targetHWnd, String toSend, Messages id)
{
	Win32.CopyDataStruct aCDS = new Win32.CopyDataStruct();

	aCDS.ID = (Int32)id;
	aCDS.Data = toSend;
	if (toSend != null)
		aCDS.Length = aCDS.Data.Length + 1;

	IntPtr aRetVal = Win32.SendMessage(targetHWnd, Win32.WM_COPYDATA, IntPtr.Zero, ref aCDS);

	return (aRetVal != IntPtr.Zero);
}

class Win32
{
    public static readonly uint WM_COPYDATA = 0x004a;

    [StructLayout(LayoutKind.Sequential)]
    public struct CopyDataStruct
    {
        public Int32 ID;
        public int Length;
        public string Data;
    }

    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
    public static extern IntPtr SendMessage(
        IntPtr windowHandle,
        uint Msg,
        IntPtr wParam,
        ref Win32.CopyDataStruct lParam
    );

}
Based in parts on http://www.codeproject.com/KB/cs/skypecontrolapicsharp.aspx.

The VFP side uses BINDEVENT() to receive data:
*========================================================================================
* Set up a handler to receive data posted with WM_COPYDATA
*========================================================================================

#define WM_COPYDATA 0x004A
Public goCOPYDATA
goCOPYDATA = CreateObject("COPYDATA_Handler")
? "handle: ", Transform(goCOPYDATA.hWND,"@0")

Define Class COPYDATA_Handler as Form

	Procedure Init
		BindEvent( This.hWND, WM_COPYDATA, This, "WndProc" )
	EndProc 
	
	Function WndProc
	Lparameters tnHwnd, tnMsg, tnWParam, tnLParam
		Local lcStruct, lnIdentifier, lcData
		lcStruct = Sys(2600,m.tnLParam,12)
		lnIdentifier = FromInt(Left(m.lcStruct,4))
		lcData = Sys(2600,FromInt(Right(m.lcStruct,4)),FromInt(SubStr(m.lcStruct,5,4)))
		? lnIdentifier, lcData
	Return 99
	
EndDefine
In this case you would need to pass goCOPYDATA.hwnd to the .NET program that wants to send data. If you have a unique window title, the .NET application can use FindWindow to search for the window handle. Unlike with sockets both applications have to run on the same machine.
--
Christof
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform