User:Wishmaster/Demo

From Miranda NG
Jump to navigation Jump to search
/* DB/Event/Added event
Called when a new event has been added to the event chain for a contact
  wParam = (MCONTACT)hContact
  lParam = (LPARAM)(HANDLE)hDbEvent
hDbEvent is a valid handle to the event. hContact is a valid handle to the
contact to which hDbEvent refers.
Since events are sorted chronologically, you cannot guarantee that hDbEvent is
at any particular position in the chain.
*/
int OnMessageEvent(WPARAM wParam, LPARAM lParam) {
	MCONTACT hContact = (MCONTACT)wParam;
	HANDLE hDbEvent = (HANDLE)lParam;
	/*
	Retrieves all the information stored in hDbEvent
	hDbEvent should have been returned by db_event_add/first/last/next/prev()
	Returns 0 on success or nonzero if hDbEvent is invalid
	Don't forget to set dbe.cbSize, dbe.pBlob and dbe.cbBlob before calling this
	service
	The correct value dbe.cbBlob can be got using db/event/getblobsize
	If successful, all the fields of dbe are filled. dbe.cbBlob is set to the
	actual number of bytes retrieved and put in dbe.pBlob
	If dbe.cbBlob is too small, dbe.pBlob is filled up to the size of dbe.cbBlob
	and then dbe.cbBlob is set to the required size of data to go in dbe.pBlob
	On return, dbe.szModule is a pointer to the database module's own internal list
	of modules. Look but don't touch.
	*/
        int cbLen = db_event_getBlobSize(hDbEvent);
        BYTE *pbBuffer = (BYTE*)mir_alloc(cbLen);
	DBEVENTINFO dbei = { 0 };
	dbei.cbSize = sizeof(dbei);
	dbei.cbBlob = cbLen;
	dbei.pBlob = pbBuffer;
	if(db_event_get(hDbEvent, &dbei) != 0)
	{
		return 0;
	}
	if (dbei.eventType == EVENTTYPE_MESSAGE) { // check for message
		// look at (char)pbBuffer
	}
        mir_free(pbBuffer);
	return 0;
}

extern "C" __declspec(dllexport) int Load()
{
	mir_getLP(&pluginInfo);
        // here you hook the event for received messages
	HookEvent(ME_DB_EVENT_ADDED, OnMessageEvent);
        // Here you do your other stuffs
	return 0;
}