LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling a char * value from a dll

Oh, and how would you program an extern int16 _____ in a dll? or any extern for that matter?
0 Kudos
Message 11 of 19
(1,922 Views)


@alrite wrote:
Oh, and how would you program an extern int16 _____ in a dll? or any extern for that matter?


In C that is not a big problem (at least if you use the same compiler for the library and the caller). In LabVIEW you can't. The LabVIEW Call Library Function is a function interface node, not an exported variable interface node.

Variables exported from a DLL are not a good idea. They are inherently not multithreading safe, and traditionally there was no common support in different compilers/linkers to support this either. Not sure if you can do that with all C compilers even nowadays.

Rolf Kalbermatter

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 12 of 19
(1,919 Views)

Not sure about the extern part.  You may have to build a wrapper DLL in C to retrieve the value and pass it to LV.

An int16 is the same as I16 in Labview.  This must be a numerical error code.  Do you have a book or manual that lists error codes and their description?  If so, you could create a look up table, like an array of clusters, with each cluster containing an error code (I16) and a description (string).  Then you could search the array for the returned error code and retrieve the description for display.

Message Edited by tbob on 01-24-2007 12:50 PM

- tbob

Inventor of the WORM Global
0 Kudos
Message 13 of 19
(1,914 Views)

Hi rolf, alrite,

      When I first started building DLLs for use under LabVIEW, I remember the "extern" directive as required - at least the instructions distributed by NI said to export functions that way.  I think this was true as late as 2000. (haven't compiled any DLLs for a while Smiley Wink - )  Anyway, I think alrite is talking about a function return value - and the "extern" shouldn't be a problem... (unless I've completely lost my mind - which is quite likely, actually...)

Cheers!

P.S. If somebody wants to start a fund - to get the smiley-face/parenthesis-issue fixed, I'll donate the first ... err ... rupee. (!)

Message Edited by tbd on 01-24-2007 11:17 PM

Message Edited by tbd on 01-24-2007 11:20 PM

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 14 of 19
(1,902 Views)


@tbd wrote:

Hi rolf, alrite,

      When I first started building DLLs for use under LabVIEW, I remember the "extern" directive as required - at least the instructions distributed by NI said to export functions that way.  I think this was true as late as 2000. (haven't compiled any DLLs for a while Smiley Wink - )  Anyway, I think alrite is talking about a function return value - and the "extern" shouldn't be a problem... (unless I've completely lost my mind - which is quite likely, actually...)


Well you could be right of course. I'm not sure what the ______ stands for in the declaration he wrote. Without anything more it is just a global variable that gets exported too (and which you actually can access with LoadLibrary()) although the specifics to access such a variable from other code can get nasty.

As to if extern is required or not: I believe it isn't or at least it won't have much influence for Visual C. In standard C functions not declared static are always considered public. The difficulty here is that public means they get exported from the compiled object file and can be linked by the linker with other object files. They get however not exported by default from a DLL.

In Visual C you can either put __declspec(dllexport) as extra specifier in front of a function (prototype) to hint to the linker to add the symbol to the DLL export table or you can define a specific .def file that lists all symbols to be exported. Borland C can also use .def files AFAIK and newer versions support declspec(dllexport) but used __export as special keyword in the source code in the past.

Rolf Kalbermatter

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 15 of 19
(1,887 Views)
I have a dll that requires a base address (0x300) to be passed in. How can that be done since in the dll it is defined as a constant?
0 Kudos
Message 16 of 19
(1,876 Views)
How can you have a dll with a paramter being defined as a constant?  It isn't possible.  If it is a constant, you can't change it, and it can't be a paramter to be passed in or out.
- tbob

Inventor of the WORM Global
0 Kudos
Message 17 of 19
(1,859 Views)
the dll is dsp_init(int16 controller_address) and the controller_address is 0x300. How do you pass the address to the dll dsp_init?
0 Kudos
Message 18 of 19
(1,855 Views)
Create an I16 in Labview and assign it a value of 0x300.  In the Call Library Node, create a parameter of I16 type, call it whatever (maybe Controller_Address), and set the Type to Numeric, Data Type to Signed 16 bit integer, and Pass to Value.  Then wire the I16 into this node.
- tbob

Inventor of the WORM Global
0 Kudos
Message 19 of 19
(1,852 Views)