Exemple #1
0
stdstr VersionInfo(LPCTSTR Info, HMODULE hModule) 
{
	TCHAR FileName[MAX_PATH];
	if (GetModuleFileName(hModule,FileName,sizeof(FileName)) != 0)
	{
		return FileVersionInfo(Info,FileName);
	}
	return TEXT("");
}
Exemple #2
0
	int cPlugs::PlugIN(const char * file , const char * cert , int ex) {
		HMODULE hModule;
		cPlug dll;
		IMLOG("* plugin - %s" , file);
		try {
			dll.priority = PLUGP_NONE;
			dll.Ctrl = 0;
			hModule = LoadLibrary(file);

			if (!hModule) {
				string err = "Load Failed [";
				int errNo = GetLastError();
				err +=inttoch(errNo);
				err +="] ";
				err +=GetLastErrorMsg(errNo);
				strcpy(TLS().buff , err.c_str());
				throw (char*)TLS().buff;
			}
			dll.IMessageProc=(fIMessageProc)GetProcAddress(hModule , "IMessageProc");
			if (!dll.IMessageProc) {
				dll.IMessageProc=(fIMessageProc)GetProcAddress(hModule , "_IMessageProc@4");
				if (!dll.IMessageProc)
					throw "IMessageProc not found!";
			}

			dll.file = file;
			dll.hModule=hModule;
			//	if (Plug.size() < 1) { // ID dla UI jest inne od pozosta³ych
			//		dll.ID = Plug.size(); 
			//	} else {
			dll.ID=(unsigned int)Plug.size()+PLUG_MAX_COUNT; // <=0x80 to identyfikatory... Do 127 wtyczek!
			//	}
			/*    if (cert) {
			char * ch = (char*)IMessageDirect(dll,IM_PLUG_CERT , 0 , 0);
			if (!ch || strcmp(cert , ch)) throw "Unsuplied CERT";
			}*/
			dll.running = true;
			dll.type=IMessageDirect(dll,IM_PLUG_TYPE , 0 , 0 , 0);
			dll.version=safeChar(IMessageDirect(dll,IM_PLUG_VERSION , 0 , 0 , 0));
			if (dll.version.empty()) {
				FileVersionInfo(dll.file.c_str() , TLS().buff2);
				dll.version = TLS().buff2;
			}
			// Zamieniamy wersje tekstowa na liczbowa...
			Stamina::RegEx reg;
			if (reg.match("/(\\d*)[., ]*(\\d*)[., ]*(\\d*)[., ]*(\\d*)/" , dll.version.c_str()))
				dll.versionNumber = VERSION_TO_NUM(atoi(reg[1].c_str()) , atoi(reg[2].c_str()) , atoi(reg[3].c_str()) , atoi(reg[4].c_str()));
			else
				dll.versionNumber = 0;
			dll.sig=safeChar(IMessageDirect(dll,IM_PLUG_SIG , 0 , 0 , 0));
			//    dll.core_v=safeChar(IMessageDirect(dll,IM_PLUG_CORE_V , 0 , 0 , 0));
			//    dll.ui_v=safeChar(IMessageDirect(dll,IM_PLUG_UI_V , 0 , 0 , 0));

			dll.net=IMessageDirect(dll,IM_PLUG_NET , 0 , 0);
			dll.name=safeChar(IMessageDirect(dll,IM_PLUG_NAME , 0 , 0 , 0));
			dll.netname=safeChar(IMessageDirect(dll,IM_PLUG_NETNAME , 0 , 0 , 0));

			if (IMessageDirect(dll,IM_PLUG_SDKVERSION , 0 , 0 , 0) < KONNEKT_SDK_V) throw "Wtyczka przygotowana zosta³a dla starszej wersji API. Poszukaj nowszej wersji!";

			if (Plug.size() > 0 && dll.net==0) throw "Bad Net value!";
			if (dll.sig=="" || dll.name=="") throw "Sig|Name required!";
			//    if (dll.core_v!="" && dll.core_v!=core_v) throw "incompatible Core";
			//    if (ui_v!="" && dll.ui_v!="" && dll.ui_v!=ui_v) throw "incompatible UserInterface";
			if (Plug.size()==0) {//ui_v=dll.sig;
			ui_sender=dll.ID;
			}
			dll.Ctrl = ex? createCorePluginCtrl() : createPluginCtrl();
			dll.Ctrl->setCtrl(dll.ID , hModule);
			dll.running = true;
			if (!IMessageDirect(dll,IM_PLUG_INIT , (tIMP)(dll.Ctrl) , (tIMP)dll.hModule , 0))
				throw "IM_INIT failed";
			if (ex) IMessageDirect(dll,IM_PLUG_INITEX , (tIMP)(dll.Ctrl) , 0 , 0);

			int pos = this->push(dll);

			if (dll.net == -1) { /* odpytujemy raz jeszcze, sam nas o to prosi³... */
				Plug[pos].net =IMessageDirect(dll,IM_PLUG_NET , 0 , 0);
				Plug[pos].name=safeChar(IMessageDirect(dll,IM_PLUG_NAME , 0 , 0 , 0));
				Plug[pos].netname=safeChar(IMessageDirect(dll,IM_PLUG_NETNAME , 0 , 0 , 0));
				if (Plug[pos].name=="") throw "Sig|Name required!";
			}
			// Wtyczka zostala zatwierdzona i dodana

			//    cPlug & plg = Plug[Plug.size()-1];


		} catch (char * er) {
			if (dll.Ctrl) {delete dll.Ctrl;dll.Ctrl = 0;}
			if (hModule) FreeLibrary(hModule);
			CStdString errMsg;
			errMsg.Format(resString(IDS_ERR_DLL).c_str() , file , er);
			int ret = MessageBox(NULL , errMsg , resStr(IDS_APPNAME) , MB_ICONWARNING|MB_YESNOCANCEL|MB_TASKMODAL);
			if (ret == IDCANCEL) abort();
			return ret == IDYES? 0 : -1;
		}
		return 1;
	}