LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

C DLL does not working in LabVIEW-2011, but works good in LabVIEW-2009

Solved!
Go to solution

The C-Language dll which I have for an instrument is working good in LV2009 without any errors, but in 2011 it throws 1097 Error code.  In this link, it is mentioned that calling convention in "Call Library Node" is changed since LV2010 which I guess could be the reason for the error.  But trgically I need to develop my code in LV2011.  Does anyone have an workaround to make the dll work in LV2011?

 

Thanks,

Ajay. 

--
Ajay MV


0 Kudos
Message 1 of 9
(3,657 Views)

Did you already tried to set calling convention to correct value?

 

0 Kudos
Message 2 of 9
(3,655 Views)

Andrey Dmitriev,

 

     I have used Import from Shared Library (Tools-->Import-->Shared Library) wizard in LabVIEW to generated the VIs for callind the methods in dll.  It has generated it automatically and when I opened the Call From Library Node from block diagram, I found that "C" is selected in Call Library Function dialogue box.  Hence, it is most likely that I have already tried to set the calling convention to the correct value.

 

-Ajay
 

--
Ajay MV


0 Kudos
Message 3 of 9
(3,635 Views)

Do you have source code of this DLL?

0 Kudos
Message 4 of 9
(3,625 Views)

No, I don't have source code. But I have a sample code of this dll.  I have attached the sample code herein.

--
Ajay MV


0 Kudos
Message 5 of 9
(3,619 Views)

Quite large amount of code. Seems to be stdcall is correct setting. But without your VI is impossible to say whats going wrong.

 

 

0 Kudos
Message 6 of 9
(3,615 Views)
Solution
Accepted by topic author Ajay_MV

I found that we should explicitly set the Calling Convention of the DLL.  I misunderstood that "C" calling convention is used for the codes developed using C/C++ Language and I was using this ("C") as calling convention in LV 2010 and LV 2011.  When I chaged to "WinAPI" as calling convention, it worked well.

 

Iam wondering, what exactly is the calling convention?

 

Thanks,

Ajay.

--
Ajay MV


0 Kudos
Message 7 of 9
(3,578 Views)

Ajayvignesh MV wrote:

I am wondering, what exactly is the calling convention?


It's an agreement between a caller and a callee on the way that parameters are passed to the function, and how the function should return values to the caller.  See the Wikipedia article on x86 Calling Conventions.

Message 8 of 9
(3,568 Views)

And the particular issue at hand is, that stdcall functions CAN have but DON'T have to have a particular naming decoration in their exported name (a @<number> appended to the name, and LabVIEW doesn't show this decoration in the drop down box). Before LabVIEW 2010 the Call Library Node automagically corrected a configured C calling configuration to stdcall if it recognized that decoration. They removed that in 2010 because it is possible, and most probably happened in the wild, for a C function to be explicitedly named with this pattern but get exported as C calling convention. With this automatic and hidden correction, LabVIEW is totally unable to call such a function.

 

The not so nice thing about this would be IMHO that this automagic correction happened sneakily in the background without even being visible at all (the option in the Call Library Node stayed C calling convention, despite that LabVIEW really decided to use stdcall). And it got made even worse by the fact that 2010 removed this sneaky correction but did not add any mutation code to correct for that, when updating a VI from a previous LabVIEW version. That all said the evil has been done and can't be reversed now. Everybody just has to live with it.

Rolf Kalbermatter
My Blog
Message 9 of 9
(3,550 Views)