The CNiDataSocket Connect function requires that your application processes Windows messages while the DataSocket is connecting. Your application can only process messages when it is not executing your code.
The reason the above works is because the constructor is called when the DLL is loaded and the DataSocket connects during the time in between the DLL being loaded and you calling GetValue.
If you put the Connect call in the Retrunvalue function so that you attempt to Connect and then retrieve a value from the DataSocket without ever leaving functions you wrote, then the DataSocket will never connect.
If the thread that your DLL is running in doesn't have any user interface objects, you can put a Windows message pump in it after you call Connect lik
e this:
CNiDataSocket::ConnectionStatus status;
do
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
status = myDataSocket.Status;
}
while ((status != ConnectionActive)
|| (status != ConnectionIdle)
|| (status != ConnectionError));
Otherwise, you will need to either do what you have written above or provide one function in your DLL to connect and another to get a value.
I hope this helps. Let me know if something is not clear or doesn't work.
Thanks,
TonyH
Measurement Studio
NI