SetCurrentConnection
Changes the current connection number for the current thread group or allocates a new connection number
#include <nwcntask.h>
LONG SetCurrentConnection (
LONG connectionNumber);
If successful, this function returns the connection number that was current when you changed it so that you can change back to it if you want to. If not successful, this function returns EFAILURE (-1).
The SetCurrentConnection function sets the current connection number for the current thread group. You can either pass -1 or a connection number. If you pass -1, you allocate a new connection number for the exclusive use of your NLM, which is made the thread group’s current connection. If you pass any other value, you change the thread group’s current connection to that value.
For example, if you have four connections, 1 through 4, and the current connection is 2, you can change the current connection to 4 by passing 4. If you get back 2, you know you have successfully changed the current connection to 4. On the other hand, if you want to allocate a new connection, you pass -1. If successful, you still get back 2, and your current connection is an unknown number, which you can identify by calling GetCurrentConnection (or by calling SetCurrentConnection again to see what it returns).
When setting connections on the local server, you can set any available connection number; however, when setting connection numbers on a remote server, you can set only those that your NLM has logged in on.
#include <stdio.h> #include <stdlib.h> #include <nwcntask.h> #include <errno.h> main() { int rc; rc = SetCurrentConnection (-1); printf ("SetCurrentConnection rc = %d\n", rc); if (rc == EFAILURE) return 1; printf("SetCurrentTask return value:%d\r\n", SetCurrentTask(5)); printf("GetCurrentConnection %d\r\n", GetCurrentConnection()); printf("GetCurrentTask (should be 5):%d\r\n", GetCurrentTask()); getch(); }