01-27-2006 05:43 AM
void AssignResponseFunction(RESPONSE_FUNC pfResponse, UCHAR *pucResponseBuffer); where RESPONSE_FUNC is a pointer to the function that will be called whenever a response / event message is received from the module.
01-27-2006 09:36 AM
It is possible to do what you are asking, but it's not the easiest thing in the world to do, and it can't be done entirely in LabVIEW. The function that receives the message must be written in C (or some other language) and compiled in a DLL. (I suppose as of 7.0 one could actually make a DLL from LabVIEW code for these purposes, but I've never tried it.) Then, you'll need to ensure that the DLL is loaded into memory and get the function pointer. Using calls to WinAPI functions (assuming you're on Windows, that is):
Now, regarding the implementation of the callback itself, you have two choices:
The first is generally easier, but not always practical. For instance, suppose that you just wanted to log the data to a file. You could pass the file handle through the pucResponseBuffer parameter (I am assuming that this is just a user parameter that is going to get passed to your callback) and then use LabVIEW File Manager calls to perform the write.
If, however, you need to have further action taken by your VI in response to the message, you will need to go with the second option. For this, I refer you to the Windows Message Queue set of VIs and, more specifically, the DLL code. In this example, a callback function is registered with the call to SetWindowsHookEx .(The call is made from within the DLL code rather than from the VI, but that difference is not important.) The callback function stores the data and fires a LabVIEW occurrence, notifying the VI to grab the data from the the DLL storage.
One thing to note about this code: it is no longer necessary to manually find the Occur function, as is done in the DllMain function as it is now listed in extcode.h.
Best Regards
Jason
08-07-2008 08:01 AM
#include
"stdafx.h"#include
<windows.h>HINSTANCE h = 0;
const
char* lib ="MeineDLL.dll";const
char* proc="DLL Funktion";extern
"C" __declspec(dllexport) int myDLLload(LPCWSTR lib){
if(h == 0){
LPCWSTR lib = libinput;
h = LoadLibrary(lib);
return 0; // ok}
return 1; // error}
// übergib addr in LabView der anderen DLL-Funktion
extern "C" __declspec(dllexport) int myDLLgetprocaddr(LPCSTR proc, int* addr){
if(h != 0){
*addr = (
int)GetProcAddress(h, proc); return *addr != 0; // ok}
return 1; // error}
extern "C" __declspec(dllexport) void myDLLFree(){
FreeLibrary(h);
}
the problem is, that the myDLLload function returns 0 all the time, no mather how i define "lib". and i think that is the reason why the myDLLgetprocaddress funktion fails to deliver me the address...
i know that you surely know much more about visual c++ than i do, so i would be very thankfull for any advice how i can solve this problem.
thank you a lot
martin
08-08-2008 10:07 AM
Hi Martin,
There is a Microsoft example on how to implement the LoadLibrary function at this link. I would try to modified your code, specifically the datatype of your lib variable, to match their implementation and see if this solves your issue.
Cheers,
Jonah
Applications Engineer
National Instruments
08-11-2008 05:10 AM