From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Callback function returns warning when compiled

Hi all!
I am using 6527 DIO board with NI-DAQ 7. I am using address of callback function instead of message when calling DIG_Change_Message_Config function. Whe I compile this program, the compiler responds with 2 warnings, stating, that I am converting from 64-bit pointer to 32 bit. I checked this with .NET documentation and it seems, that all pointers in .NET are 64-bit long. Function DIG_Change_Message_Config requests u32 pointer, which is 32-bit. Any suggestions?
0 Kudos
Message 1 of 13
(4,088 Views)
Kovalenkov,

Anytime you (or the compiler) casts a pointer from a larger size (like 64-bit) down to a smaller size (like 32-bit) you risk data loss. If you are being forced to pass in a 64-bit pointer to a function that only accepts a 32-bit pointer I�m not sure that there is much you can do. Since you are receiving compiler warnings then most likely the compiler is doing the conversion for you and it�s warning you that bad things might happen. I would check the .NET documentation again to ensure that your only options are to indeed use a 64-bit pointer. If at all possible you want to pass in pointers of the same size.

You may want to check out this document. It
discusses some of the issues in working with the NI-DAQ function �DIG_Change_Message_Control()�. If this advise fails to help you out then please post again (with more details such as OS, specific .NET language being used, compiler, etc�)and I will look further into the issue. Good luck!

Craig H.
National Instruments
0 Kudos
Message 2 of 13
(4,088 Views)
Thank you for your reply.
First I would like to ask you to re-submit the link, since it does not seem to work.
Now. I am using Visual C++ .NET 2003 on Windows XP.
My callback function is declared like this:
'static void mycallback(HWND handle, UINT message, WPARAM wParam, LPARAM lParam);'

I am calling DIG_Change_Message dunction like this:
'DIG_Change_Message_Config (iDeviceNumber, 1, pszRisingEdge, pszFallingEdge, 0, 0, (u32)mycallback);'
0 Kudos
Message 3 of 13
(4,088 Views)
kovalenkov,

I have a couple of ideas. Do you happen to be running a 64-bit version of Windows XP? Unfortunately the NI-DAQ DLL call needs a 32-bit address to your callback function as a parameter. 64-bit pointers are only needed when using a 64-bit operating system.

You may want to contact Microsoft support or check the online MSDN to see if there is some way in Visual C++ to make the pointer to your callback function 32-bit instead of 64-bit. 64-bit pointers should not be used in 32-bit applications. I find this strange as I am not positive that a 64-bit .NET has been released yet.

The link from my previous post appears to be working correctly but now that I know you are using Visual C++ it doesn�t address your problem. Unfortunately
this appears to be an issue with .NET. Perhaps someone in the community has some experience with this and can provide better help. Good luck!

Craig H.
National Instruments
0 Kudos
Message 4 of 13
(4,088 Views)
Craig,

I am using regular 32-bit Windows XP on my computer. The problem is though, that Microsoft introduced 64-bit pointers instead of 32-bit in Visual Studio .NET 2003. I am not sure for previous .NET versions, but I am pretty sure, that VS 6.0 used 32-bit pointers.

Thanks for your help.
0 Kudos
Message 5 of 13
(4,088 Views)
Kovalenkov,

You may want to look into NI's Measurement Studio for your application development. The NI-DAQ software integrates seemlessly with Measurement Studio and should fix your problem. For more info on Measurement Studio follow this link: "NI Measurement Studio".

Please post back with any other questions.

Craig H.
National Instruments
0 Kudos
Message 6 of 13
(4,088 Views)
Craig,

I understand, that NI Measurement Studio should be a prefered choice by NI, but the company I work for feels that the code should be written in pure C++ with as less 3rd party products as possible. We thought there would be no serious problem with this approach, since NI assures to their customers, that this approach can indeed be used.
NI Measurement Studio is therefor out of the question.
0 Kudos
Message 7 of 13
(4,088 Views)
kovalenkov,

Hopefully we are getting closer to solving your problem! I have uncovered a knowledge base that may address your needs:

"Programming DAQ in Visual C++ .NET"

The use of the callback function in this scenario requires the use of Traditional DAQ, so ensure that you are using it. It seems like you are doing everything correctly so this seems to be an issue with Visual C++.

The Traditional DAQ function that you are using needs to be fed a 32-bit function pointer and I am not sure why Visual C++ is handing off a 64-bit function pointer. Are you getting faulty data as a result of warning? I'
ll continue to do more research on this and will post back with any new findings.

Craig H.
National Instruments
0 Kudos
Message 8 of 13
(4,088 Views)
Craig,

Million thanks to you. I am using Traditional DAQ. The warning, which is returned when compiled is this:
>warning C4311: 'type cast' : pointer truncation from 'void (__cdecl *)(HWND,UINT,WPARAM,LPARAM)' to 'u32'<
which according to MSDN means:
'A 64-bit pointer was truncated to a 32-bit int or 32-bit long.'

Hope that helps.
0 Kudos
Message 9 of 13
(4,088 Views)
I am not getting faulty data, while running application on test system. But the test system is on and off, while in real life system this application would have to run correctly 24 hours a day 7 days per week and so on. Thus, we can not afford any glitches in the application. And pointer warnings can cause some very weird malfunctions to the application.
0 Kudos
Message 10 of 13
(4,088 Views)