Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Working with sockets
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01339151
Message ID:
01340155
Views:
21
Not sure I understand how this is working:
lcStruct = ;
toInt(m.lnIdentifier,4) + ;
toInt(Len(m.lcData),4) + ;
toInt(m.lnMem+12,4) + ;
m.lcData
What is toInt here?
Sorry if I am missing something obvious.


>Hi Mark,
>
>Here's the C# code. It works with a default console application. You only need to add System.Windows.Forms.dll to the References section:
>
>using System;
>using System.Collections.Generic;
>using System.Text;
>using System.Windows.Forms;
>using System.Runtime.InteropServices;
>
>namespace ConsoleApplication6
>{
>	class Program
>	{
>		static void Main(string[] args)
>		{
>			Form f = new MyForm();
>			f.Show();
>			f.Hide();
>			ApplicationContext ctx = new ApplicationContext();
>			Application.Run(ctx);
>		}
>	}
>
>	class MyForm : Form
>	{
>		const int WM_COPYDATA = 0x004a;
>
>		public MyForm()
>		{
>			Text = "my_unique_id";
>		}
>
>		protected override void WndProc(ref System.Windows.Forms.Message m)
>		{
>			switch (m.Msg)
>			{
>				case WM_COPYDATA:
>					COPYDATASTRUCT mystr = new COPYDATASTRUCT();
>					Type mytype = mystr.GetType();
>					mystr = (COPYDATASTRUCT)m.GetLParam(mytype);
>					MessageBox.Show(mystr.Data);
>					break;
>			}
>			base.WndProc(ref m);
>		}
>	}
>	[StructLayout(LayoutKind.Sequential)]
>	public struct COPYDATASTRUCT
>	{
>		public Int32 ID;
>		public int Length;
>		public string Data;
>	}
>}
>
>Here's the corresponding VFP code.
>
>* Find handle
>Local lnHandle
>Declare Long FindWindow in Win32API String, String
>lnHandle = FindWindow(NULL,"my_unique_id")
>
>*Declare API functions
>Declare Long HeapAlloc in win32api Long, Long, Long
>Declare Long GetProcessHeap in win32api
>Declare Long HeapFree in win32api Long, Long, Long
>#define WM_COPYDATA 0x4A
>
>* Create a COPYDATASTRUCT structure *
>Local lcStruct, lnMem, lcData, lnIdentifier
>lcData = "Hello World"+Chr(0)
>lnIdentifier = 1
>lnMem = HeapAlloc( GetProcessHeap(), 0, Len(m.lcData)+12 )
>lcStruct = ;
>toInt(m.lnIdentifier,4) + ;
>toInt(Len(m.lcData),4) + ;
>toInt(m.lnMem+12,4) + ;
>m.lcData
>Sys(2600,m.lnMem,Len(m.lcStruct),m.lcStruct)
>
>*Send data to the other application *
>Local lnRetVal
>Declare Long SendMessage in win32api Long, Long, Long, Long
>lnRetVal = SendMessage( m.lnHandle, WM_COPYDATA, _VFP.Hwnd, lnMem )
>
>* Free up memory *
>HeapFree( GetProcessHeap(), 0, m.lnMem )
>
>Execute the Console application first, then the VFP application. Anything passed from the VFP application is displayed in a messagebox by the C# application. You might have to use ALT+TAB since the C# application does not automatically come to front. In the console you can press Ctrl+C to terminate the application.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform