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 comment

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 comment

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 comment

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 comment

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 comment

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.

×
×
  • Create New...

Important Information

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