LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Advanced implementation of existing C++ code

I have been trying to implement some previously written C++ code for a project and came to the code below which has stumped me. The actual functionality is in regards to resolving a host destination by name instead of a dotted IP address--which I'm aware I can do with the native LabVIEW function. What I can't figure out is any implementation of code, such as the example below, where I am trying to get data placed in memory using a pointer returned by the function call. It seems like there should be a way to do this.


TYPEDEF STRUCT hostent {
CHAR FAR* h_name;
CHAR FAR FAR** h_aliases;
SHORT h_addrtype;
SHORT h_length;
CHAR FAR FAR** h_addr_list;
} hostent;

hostent* hp = gethostbyname(host);
addr
esstype = hp->h-addrtype;

Documentation for gethostbyname():

STRUCT hostent* FAR gethostbyname {
CONST CHAR* name};
0 Kudos
Message 1 of 6
(2,979 Views)
Correct me if I'm wrong, but you are saying that LabVIEW can only resolve by IP, and not by name?

LabVIEW can easily resolve by name or by IP address, you can even select "multiple output" and get ALL assigned IPs (very nice!).

The following LabVIEW code fragment (image attached) accepts names or dotted decimal IP address strings. The format of the output depends on the boolean constant (dotted decimal(T) vs. hostname(F))
0 Kudos
Message 2 of 6
(2,979 Views)
I'm aware of what I can and can't do with the LabVIEW network functions... I was asking more along the lines of how do I implement the C++ code as written where the function call returns a pointer to a struct with information in it.
0 Kudos
Message 3 of 6
(2,979 Views)
This link

http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B45EACE3E78F56A4E034080020E74861&p_node=DZ52048&p_source=external


Has an example that illustrates how to pass different data types to/from a dll. If you knew this already, please forgive the distraction.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 6
(2,979 Views)
I have looked at this already and it is not quite what I need.

After thinking some, I'm wondering since the three options for return type are void, numeric and string, if it is possible to set the return type to string and use the CStr ptr type to access the data then convert it to an array.
0 Kudos
Message 5 of 6
(2,979 Views)
Hi m3nth,

I am definatelty working outside my comfort zone now. I will offer what I do have.

Yes, I believe your idea could work.

Have you tried using the "create .c file" option available by popping up on the Call Libary Function node? This will create a C structure based on the data structures wired to the node. This option will let you work with the clusters format and order to get cluster you pass to show up as the structure you are after.

I used this technique in a project about 5 years ago. It took a little time to figure what was happening (i.e. relation between cluster item names and fileds of the structure, cluster order, etc) but it worked for me.

If you start with the example in the lower right corner of the link I posted y
ou should see what I I am talking about.

If any of the data types gives you trouble, you may want to post a new question focusing on that.

As before, if you knew this already forgive the distraction.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 6 of 6
(2,979 Views)