Jump to content

Windows messaging between 2 VIs?


Recommended Posts

At http://zone.ni.com/d...a/epd/p/id/4394, NI provides some example code for using Windows Messaging in Labview 2009. But the example generates and intercepts the messages in the same single toplevel VI. Is it possible to converse between two VIs using Windows Messaging? Would I need (or be able) to create a new DLL in order to do that?

Toplevel:

post-4616-0-52371800-1335959057_thumb.pn

Create Windows Message Queue:

post-4616-0-35151000-1335959063_thumb.pn

From the Readme file:

**How it works**

A DLL included does all of the dirty work. The VIs in the library are primarily

wrappers around the DLL with the exception of Wait for Windows Message.vi.

When creating the first Windows message queue, the DLL installs a windows Get Message Hook and a CallMsgProc Hook on the LabVIEW process. This allows the DLL to inspect all messages heading for LabVIEW before LabVIEW processes them. The hook function determines whether each individual message is a message in which the queue is interested. If it is, it adds the message to the queue, and sets an occurrence. The Wait on Windows Message.vi is waiting on the same occurrence, and thus it continues its execution, retrieving the message from the queue. A number of utility functions are also provided for working with the queue.

--------

Any advice appreciated, even if it's "abandon all hope". (I'm a very weak C programmer.) I'm attaching the CPP code for the DLL, as a text file.

Windows Messages for LabVIEW.txt

Edited by torekp
Link to post
Share on other sites

At http://zone.ni.com/d...a/epd/p/id/4394, NI provides some example code for using Windows Messaging in Labview 2009. But the example generates and intercepts the messages in the same single toplevel VI. Is it possible to converse between two VIs using Windows Messaging? Would I need (or be able) to create a new DLL in order to do that?

Toplevel:

post-4616-0-52371800-1335959057_thumb.pn

Create Windows Message Queue:

post-4616-0-35151000-1335959063_thumb.pn

From the Readme file:

**How it works**

A DLL included does all of the dirty work. The VIs in the library are primarily

wrappers around the DLL with the exception of Wait for Windows Message.vi.

When creating the first Windows message queue, the DLL installs a windows Get Message Hook and a CallMsgProc Hook on the LabVIEW process. This allows the DLL to inspect all messages heading for LabVIEW before LabVIEW processes them. The hook function determines whether each individual message is a message in which the queue is interested. If it is, it adds the message to the queue, and sets an occurrence. The Wait on Windows Message.vi is waiting on the same occurrence, and thus it continues its execution, retrieving the message from the queue. A number of utility functions are also provided for working with the queue.

--------

Any advice appreciated, even if it's "abandon all hope". (I'm a very weak C programmer.) I'm attaching the CPP code for the DLL, as a text file.

Why in all of the world do you want to use Windows messages to communicate between two VIs? This has only disadvantages, from being a platform specific solution, to making everything rather complicated, to being of low performance!

Link to post
Share on other sites

I'm not very familiar with the Windows Message scheme or the library you mention, but it is absolutely possible to implement your own messages for communication. There's some insight in this StackOverflow post, but I suspect that the library you're using does not support sending messages. Whether this functionality should be adding to the DLL or if it can be done directly from LabVIEW is unknown to be, but from the work I have done with Windows Messages, it should be pretty straightforward to do unless you want to pass complex data structures.

However, Rolf brings up a good question - there already several constructs in LabVIEW which already facilitate this kind of messaging, and natively to boot. Are you trying to overcome a process barrier or something else? What is your use case?

Link to post
Share on other sites

I'm not about to try to set this up just to test it, but I'm pretty sure you can send messages between VIs using this DLL. Messages are sent to specific windows; in the image you posted, you can see that it gets the title of the VI window, which in turn is used to retrieve the window handle. The comments in the DLL code suggest that it can handle multiple queues, one for each window. So, it should work.

Link to post
Share on other sites

Thanks folks! I will look into your suggestions ASAP. As to why: it's not my choice. It's pretty much forced on me by an equipment vendor who wrote some highly unreadable Labview code that can only do what I want via Windows messaging. Unless I learn even more C programming than I already seem to be stuck with. They provide a sketch of some C code using Windows messaging, but you have to fill in some blanks.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Similar Content

    • By drjdpowell
      View File Messenger Library
      An extensive library for passing messages between parallel processes. Generalizes the communication method, allowing the message sender to use the method provided by the receiver. Supported communication methods include wrappings of simple queues, user events, and notifiers, as well a more complex channels such as a TCP server and client. In addition, one can configure simple forwarding addresses (“Observers"), which can send messages to multiple destinations, optionally with modifications such as adding a prefix to the message label, relabelling, or substituting a different message.
      Communication patterns supported include request-reply (asynchronous or synchronous), where the reply is sent to a "reply address" attached to the request, and register-notify, where one process sends a registration message to another in order to subscribe to a series of updates.  Also supports scatter-gather, the gathering of replies from multiple senders into an array of messages.
      An option framework for dynamically-launched VI "actors" is also provided, including example templates, which can be accessed via the Tools menu (from an open Project, select Tools>>Messenger Library>>Create Actor from Template..).  An "Actor Manager" debug tool is also installed under the Tools menu.  Please note that this package has nothing directly to do with the NI Actor Framework (other than both packages are influenced by the Actor Model).
      ***Introductory Videos are on a YouTube channel.***
      ***A great summary of many Messenger Library sources, provided by Bob W Edwards***
      JDP Science Tools group on NI.com.
      Original conversation on this work is here.

      Now hosted on the LabVIEW Tools Network (but note that the latest version will often be on LAVA)
      ***NOTE: latest versions require VIPM 2017 or later to install.***
      Submitter drjdpowell Submitted 11/27/2012 Category LabVIEW Tools Network Certified LabVIEW Version 2013 License Type BSD (Most common)  
    • By drjdpowell
      An extensive library for passing messages between parallel processes. Generalizes the communication method, allowing the message sender to use the method provided by the receiver. Supported communication methods include wrappings of simple queues, user events, and notifiers, as well a more complex channels such as a TCP server and client. In addition, one can configure simple forwarding addresses (“Observers"), which can send messages to multiple destinations, optionally with modifications such as adding a prefix to the message label, relabelling, or substituting a different message.
      Communication patterns supported include request-reply (asynchronous or synchronous), where the reply is sent to a "reply address" attached to the request, and register-notify, where one process sends a registration message to another in order to subscribe to a series of updates.  Also supports scatter-gather, the gathering of replies from multiple senders into an array of messages.
      An option framework for dynamically-launched VI "actors" is also provided, including example templates, which can be accessed via the Tools menu (from an open Project, select Tools>>Messenger Library>>Create Actor from Template..).  An "Actor Manager" debug tool is also installed under the Tools menu.  Please note that this package has nothing directly to do with the NI Actor Framework (other than both packages are influenced by the Actor Model).
      ***Introductory Videos are on a YouTube channel.***
      ***A great summary of many Messenger Library sources, provided by Bob W Edwards***
      JDP Science Tools group on NI.com.
      Original conversation on this work is here.

      Now hosted on the LabVIEW Tools Network (but note that the latest version will often be on LAVA)
      ***NOTE: latest versions require VIPM 2017 or later to install.***
    • By torekp
      Supposedly there are Labview tools available at
      http://www.lvs-tools.co.uk/software/utilities/
      But whenever I try to register or login, nothing happens.  (Also, I try to think, but nothing happens.)  Are there any other Labview codes that use the Windows Memory-Mapped Files functions, or should I just reinvent this wheel?  By the way, here is a Microsoft document on the subject: https://msdn.microsoft.com/en-us/library/ms810613.aspx
    • By _Y_
      We use USB-connected Microsoft Smart Card Reader. The devise crashes sometimes. It does not happen often thus search for the reason could take time.
      The only way to get the devise functioning again, is to open Device Manager, click Uninstall then Scan for hardware changes (that installs the Reader again).
      Is there any method to do this from LabVIEW? I.e. send commands to reinstall the USB device?
      I know this could be a bad fix. However, it can help in long-time tests (while we are searching for reason of these crushes).
      Thank you
    • By Jillu Pravin
      Hi all ,
      Need help regarding the Vi i have made which works fine with labVIEW pane.Which i need to capture in windows screen.
      I have attached the vi which works great in labVIEW pane and records each event of click inside the pane.i haven't find any options in event structure for capturing mouse events out side the pane (ie which captures windows UI ) .  I know i could make it with while loop capturing mouse coordinates still i feel its not a reliable way to record .So please let me know how to make it in Event structure or is there any reliable way to make without event structure.
       
       
       
       
       
       
      Capture tool LabVIEWpane.vi
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.