Programming environment VC.NET
Implementation: Realizing server events without attributes
Customer call ATL, motivation when the ATL is completed, the customer responds to it, call the response function.
Question: The first work project is successful, the second continued call ATL failed, prompt reading memory error
My implementation method: Implement the corresponding code in the server according to the rules (reference book: vc.net book)
Part of code is: void _stdcall updata (void * p) {
/ / Update the data thread, or implement other features, omitted here, the last two sentences are indicated in the update completion activation event
CDBObject * p = (cdbobject *) p;
PP-> fire_finishupdata (); // has WIZ generation response code
}
STDMETHODIMP CDBJECT :: DOSMETHING () // Interface method
{DWORD TID;
CreateThread (0, 0, (LPTHREAD_START_ROUTINE) UPDATA, (VOID *) THIS, 0, & TID);
Return S_OK;
}
Implement a corresponding partial code in the client according to the rules (reference book: vc.net
Void onrun () // Function ONRUN Call ATL
{
Coinitialize (NULL);
_Module.init (null, getModuleHandle (NULL)); // _ module is CCOMMODULE class
Try {
IDBOBJECTPTR P (CLSID_DBOBJECT);
CEVENTHANDLER EH; / / Custom class, derive from IdispeventImpl, and add a function response event (function only bounce out a dialog)
EH.DISPEVENTADVISE (P);
P-> DOSMETHING ();
Sleep (1000); // Monitor working for a second
Eh.dispeventunadvise (P);
}
Catch (...)
{...}
_Module.Term ();
Couninitialize ();
}