Messaging interop between c# and VB6 mdi applications -


i have 2 mdi applications, both of retrieve data same database. 2 applications need able send messages each other keep in synch. messages being passed , forth contain string telling recieving application piece of data in database should looking @ (a job number, , additional related info). both applications have message handler, instantiated when each program starts up.

when message sent vb6 app c# app sees message, , acts appropriately, when send same type of message c# app vb6 app, seems see message event, when unpacking it, sees part of data, , ignores message.

i'm thinking may formatting wrong on c# end. here method sends message:

namespace interprocessmessaging { [structlayout(layoutkind.sequential)]     public struct copydatastruct     {         public intptr dwdata;//a pointer number use identify message         public intptr lpdata;//a pointer address of data         public intptr cbdata;//a pointer number of bytes transferred       }  public class clsmessaging : system.windows.forms.nativewindow, idisposable  {  //api function send async. message target application         [dllimport("user32.dll", charset = charset.ansi)]         public static extern intptr sendmessagea(intptr hwnd, int32 wmsg, int32 wparam, copydatastruct lparam);    public void sendmessagetovb6(string sendmsg, string windowsapptitle)   {             try             {                  intptr hwndtarget = findwindow(null, windowsapptitle);                  intptr pdwdata = marshal.allochglobal(sizeof(int32));//a pointer number used identify message                 marshal.structuretoptr(3, pdwdata, true);//place value 3 @ location                  intptr plpdata = marshal.stringtohglobalansi(sendmsg.trim());//a pointer address of data                  intptr pcbdata = marshal.allochglobal(sizeof(int32));//a pointer number of bytes transferred                  marshal.structuretoptr(sendmsg.trim().length+1, pcbdata, true);//place size of string @ location                  copydatastruct cds;//a structure containing 3 pointers above                 cds.dwdata = pdwdata;//a pointer number used identify message (3)                 cds.lpdata = plpdata;//a pointer address of data                 cds.cbdata = pcbdata;//a pointer number of bytes transferred                     if (!system.intptr.zero.equals(hwndtarget))                 {                     sendmessagea(hwndtarget, 74, 0, cds);                 }             }             catch (exception ex)             {                 debug.print(ex.innerexception.tostring());             }   }  } } 

i recommend named pipes. in .net can use system.io.pipes purpose. in vb6 can implement win32api. named pipes better way make ipc windows messaging. ipc via sendmessage has limitations on vista , win7.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -