using System.Runtime.InteropServices;
const int WM_COPYDATA = 0x004A;
[DllImport("coredll.dll")]private static extern int FindWindow(string
lpClassName, string lpWindowName); //works great
[DllImport("user32.dll")]static extern bool SendMessage(IntPtr hWnd, int
Msg, IntPtr wParam, ref COPYDATASTRUCT lParam);
public struct COPYDATASTRUCT
{
public IntPtr dwData;
public int cbData;
public char[] lpData; //public IntPtr //[MarshalAs(UnmanagedType.LPStr)]
}
private void button1_Click(object sender, System.EventArgs e)
{
IntPtr iAPHwnd;
COPYDATASTRUCT oCDS;
string sScript = "Application.Quit";
iAPHwnd = (IntPtr)FindWindow("AfxArcPad Class", null);
//MessageBox.Show(iAPHwnd.ToString()); //This works
oCDS.cbData = (sScript.Length * 2) + 1; //not sure if I needed to do this
for unicode - should allocate enough space in any case
oCDS.lpData = sScript.ToCharArray();
oCDS.dwData = (IntPtr) 1;
SendMessage(iAPHwnd, WM_COPYDATA, (IntPtr)null, ref oCDS); //get a managed
notsupportedexeception
}
[DllImport("coredll.dll")]
private static extern IntPtr LocalAlloc(int flag, int size);
[DllImport("coredll.dll")]
private static extern IntPtr LocalFree(IntPtr p);
public struct COPYDATASTRUCT
{
public int dwData;
public int cbData;
public IntPtr lpData; //public IntPtr //[MarshalAs(UnmanagedType.LPStr)]
}
COPYDATASTRUCT oCDS = new COPYDATASTRUCT();
oCDS.cbData = (sScript.Length + 1) * 2;
oCDS.lpData = LocalAlloc(0x40, oCDS.cbData);
Marshal.Copy(sScript.ToCharArray(), 0, oCDS.lpData, sScript.Length);
oCDS.dwData = 1;
SendMessage(...)
LocalFree(oCDS.lpData);
"microsoft.public.windowsce.embedded" <sd...@sdfa.asd> wrote in message
news:e7fxPtptCHA.1776@TK2MSFTNGP09...
This is where it gets fun!
-Chris
"Alex Feinman" <publi...@alexfeinman.com> wrote in message
news:e1dUT5ptCHA.2492@TK2MSFTNGP10...
How's that? <g>
"Chris Tacke, eMVP" <cta...@NOinnovativedssSPAM.com> wrote in message
news:OQRnzCstCHA.2492@TK2MSFTNGP11...