LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling function wsastartup() of wsock32 DLL

Could someone tell me how to use the function "wsastartup()" of wsock32.dll to initial a network connection?

Here is the definition of the wsastartup() function:

int WSAStartup(
__in WORD wVersionRequested,
__out LPWSADATA lpWSAData
);

Parameters

wVersionRequested [in]

The highest version of Windows Sockets specification that the caller can use.

The high-order byte specifies the minor version number; the low-order byte specifies the major version number.

lpWSAData[out]

A pointer to the WSADATA data structure that is to receive details of the Windows Sockets implementation.

Return Value

If successful, the WSAStartup function returns zero. Otherwise, it returns one of the error codes listed below.

 

For more wsastartup() detail, please visiti

http://msdn.microsoft.com/en-us/library/ms742213%28VS.85%29.aspx

 

I've tried many times and that cause labview to crash.

Please give an example, thanks.

 

Devin

 

 

0 Kudos
Message 1 of 12
(4,224 Views)
Can you post what you have did so far. We need to check how you have handled WSADATA structure. Please post the code and not a screenshot.
0 Kudos
Message 2 of 12
(4,216 Views)

That's the problem. I don' know how to handle WSADATA structure and create a pointer.

I asked NI engineer for help and they told me to use C string pointer but it can't work.

What type should I select in the page "Parameters" of Call Library Function window?

Thanks a lot!

 

Devin

0 Kudos
Message 3 of 12
(4,199 Views)

Well you can't create in LabVIEW easily a structure that would match the WSADATA structure, because of the last string pointer in that structure. However you might get away with setting this member to 0.

 

You would then create a byte array that has following length:

 

typedef struct WSAData {
WORD wVersion; 2
WORD wHighVersion; 2
char szDescription[WSADESCRIPTION_LEN+1]; 256 + 1
char szSystemStatus[WSASYS_STATUS_LEN+1]; 128 + 1
unsigned short iMaxSockets; 2
unsigned short iMaxUdpDg; 2
char FAR *lpVendorInfo; 4
} WSADATA, *LPWSADATA;

 I'm sure you can add the numbers up yourself.

 

But you do not need to call WSAStartup or WSAShutdown in a LabVIEW program since LabVIEW has done that already before it started up and will call the WSAShutdown function when it closes.

Rolf Kalbermatter
Averna BV
Message 4 of 12
(4,188 Views)
I have a more basic question: what are you trying to do? And I'm not referring to the attempt to call this function. I'm referring to what you're trying to code up. What are you trying to do that you cannot do with the LabVIEW built-in TCP/IP functions?
0 Kudos
Message 5 of 12
(4,182 Views)

Thanks, Rolf.

I want to calculuate the throughput of network transmission between two computers, so I asked NI engineer 

and they told me to call Windows API to solve this problem.

I didn't  know that Labview with network functions can be used and now I find where they are  for solving my problem.

 

Devin

 

0 Kudos
Message 6 of 12
(4,160 Views)
The LabVIEW network functions don't operate at that low of a level. Based on what you are looking to get, it seems to me that a third-party software solution would be far easier to use than to try to call Windows API functions from LabVIEW. Have you tried Google to find such software?
0 Kudos
Message 7 of 12
(4,137 Views)

smercurio_fc wrote:
The LabVIEW network functions don't operate at that low of a level. Based on what you are looking to get, it seems to me that a third-party software solution would be far easier to use than to try to call Windows API functions from LabVIEW. Have you tried Google to find such software?

I would say it depends what network throughput numbers the OP wants to calculate. If sending out data through TCP/IP to some remote location and calculating the maximum or average possible throughput from that it could certainly be done in native LabVIEW. One thing to watch out here is that LabVIEW uses the network socket API in a specific way that is for instance not suited for high througput server applications. So the numbers calculated in such a way would be meaningful in comparison with each other but not necessarely a good indication what a high througput server application could achieve using overlapped and/or I/O Completion Ports Winsock calls.

 

If it is about generic data about the winsock usage then there are IPHLP.DLL APIs to get at some of that data and some is available through the registry in the Performance data section.

Rolf Kalbermatter
Averna BV
0 Kudos
Message 8 of 12
(4,108 Views)

Hello!

 

Here is your solution.

Have a look on attached pictures.

Download All
0 Kudos
Message 9 of 12
(2,105 Views)

Please note that for every successful call of WSAStartup, you also have to make an according call to WSACleanup. Otherwise when LabVIEW tries to shutdown and calls WSACleanup for its own WSAStartup call, the winsock library and any helper libraries will remain loaded and may have to be force closed by Windows on termination of the LabVIEW process, which may or may not cause crashes.

Rolf Kalbermatter
Averna BV
Message 10 of 12
(2,101 Views)