Microsoft DirectX 9.0 SDK Update (Summer 2003) |
hr = CoCreateInstance(CLSID_DirectPlay8NATResolver, NULL, CLSCTX_INPROC_SERVER, IID_IDirectPlay8NATResolver, (LPVOID*) &g_pDPNATResolver); . . . hr = g_pDPNATResolver->Initialize(NULL, DirectPlayMessageHandler, 0);
The IDirectPlay8ThreadPool interface can be used to control threading for the IDirectPlay8NATResolver interface. If you choose to use IDirectPlay8ThreadPool, that interface should be initialized and configured first.
if (g_dwPort > 0) { hr = pDP8AddrLocal->AddComponent(DPNA_KEY_PORT, &g_dwPort, sizeof(DWORD), DPNA_DATATYPE_DWORD); } hr = g_pDPNATResolver->Start(&pDP8AddrLocal, 1, 0);
The IDirectPlay8NATResolver interface only generates one callback to the application's message handler, DPN_MSGID_NAT_RESOLVER_QUERY. The message contains the address of the query sender and the device on which it was received. The application can allow DirectPlay to respond to the query by returning DPN_OK from its message handler, or ignore it by returning a failure code. This is shown in the following example.
case DPN_MSGID_NAT_RESOLVER_QUERY: { DPNMSG_NAT_RESOLVER_QUERY *pMsgNATResolverQuery = (DPNMSG_NAT_RESOLVER_QUERY*) pMsgBuffer; . . . if (bIgnoreQuery) { // Return failure to ignore the query. return DPNERR_GENERIC; } // Return OK so that DirectPlay will reply. . . . }
The DPNMSG_NAT_RESOLVER_QUERY structure also contains a pointer to the user string, or NULL if the string was not specified. This string is the same as the DPNA_NAT_RESOLVER_USER_STRING component included in the querying application's device address specified to IDirectPlay8Peer::Host, IDirectPlay8Peer::EnumHosts, IDirectPlay8Peer::Connect, IDirectPlay8Server::Host, IDirectPlay8Client::EnumHosts, or IDirectPlay8Client::Connect. The user string is sent in clear text, so you should encrypt the string if it contains sensitive data.
See NATResolver for an example usage of this interface.