LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

calling labwindows dll with callback from c# with delegate

Hi,

I am currently trying to 'consume' a dll written in LabwindowsCVI which uses callbacks in a c# windows application using delegates, does anyone have any small working examples of how to do this ?

Thanks

Paul

0 Kudos
Message 1 of 3
(3,317 Views)

Hi Paul,

I wasn't able to find any C# examples for you but I did find some resources that may help you get started.

Is the LabWindows/CVI DLL written? If not, you can find information on building one in the following application note:

http://zone.ni.com/devzone/conceptd.nsf/webmain/A32E309A55A45CA08625686900623295?OpenDocument

I had a search around on Google and found the following example on how to call a C++ DLL in C# which you could try modifying:

http://zone.ni.com/devzone/conceptd.nsf/webmain/A32E309A55A45CA08625686900623295?OpenDocument

Good luck with it,

SarahB

NI | UK

 

Sarah

Applications Engineer | National Instruments | UK & Ireland
0 Kudos
Message 2 of 3
(3,297 Views)
Thanks,

The dll is already written.
I was having one of those days yesterday where I went with an initial assumption and stuck with it (that I should pass the delegate to the dll).
This morning I had a 'light bulb' moment when I noticed that it required a uint for the callback which was an id to a registered windows message, Now I have working code by using the following pieces of code

1) override the wndproc function to look for messages that I need to handle.

        protected override void WndProc(ref Message m)
        {
            if (m.Msg == m_comms.CALLBACK_Acq)
            {
                m_comms.OnAcqStatusCallback(ref m);
            }
            base.WndProc(ref m);
        }

2. Register a callback message
            CALLBACK_Acq = RegisterWindowMessage("ACQCALLBACK");

3.  Unpack the returned LParam pointer.
      
        public void OnAcqStatusCallback(ref Message m)
        {
            ACQMgsStruct amsg = (ACQMgsStruct)Marshal.PtrToStructure(m.LParam, typeof(ACQMgsStruct));
        }

Regards

Paul
0 Kudos
Message 3 of 3
(3,293 Views)