void lvDCOMInterface::getLabviewValue(const char* param, std::string* value)
{
	if (value == NULL)
	{
		throw std::runtime_error("getLabviewValue failed (NULL)");
	}
	if (param == NULL || *param == '\0')
	{
		throw std::runtime_error("getLabviewValue: param is NULL");
	}
	CComVariant v;
	char vi_name_xpath[MAX_PATH_LEN], control_name_xpath[MAX_PATH_LEN];
	_snprintf(vi_name_xpath, sizeof(vi_name_xpath), "/lvinput/section[@name='%s']/vi/@path", m_configSection.c_str());
	_snprintf(control_name_xpath, sizeof(control_name_xpath), "/lvinput/section[@name='%s']/vi/param[@name='%s']/read/@target", m_configSection.c_str(), param);
	CComBSTR vi_name(doPath(vi_name_xpath).c_str());
	CComBSTR control_name(doXPATH(control_name_xpath).c_str());
	if (vi_name.Length() == 0 || control_name.Length() == 0)
	{
		throw std::runtime_error("getLabviewValue: vi or control is NULL");
	}
	getLabviewValue(vi_name, control_name, &v);
	if ( v.ChangeType(VT_BSTR) == S_OK )
	{
		*value = CW2CT(v.bstrVal);
	}
	else
	{
		throw std::runtime_error("getLabviewValue failed (ChangeType BSTR)");
	}
}
/// Helper for EPICS driver report function
void lvDCOMInterface::report(FILE* fp, int details)
{
	fprintf(fp, "XML ConfigFile: \"%s\"\n", m_configFile.c_str());
	fprintf(fp, "XML ConfigFile section: \"%s\"\n", m_configSection.c_str());
	fprintf(fp, "lvDCOMConfigure() Options: %d\n", m_options);
	fprintf(fp, "DCOM Target ProgID: \"%s\"\n", m_progid.c_str());
	fprintf(fp, "DCOM Target Host: \"%s\"\n", m_host.c_str());
	fprintf(fp, "DCOM Target Username: \"%s\"\n", m_username.c_str());
//	fprintf(fp, "Password: %s\n", m_password.c_str());
	std::string vi_name;
	for(vi_map_t::const_iterator it = m_vimap.begin(); it != m_vimap.end(); ++it)
	{
		vi_name = CW2CT(it->first.c_str());
		fprintf(fp, "LabVIEW VI: \"%s\"\n", vi_name.c_str());
	}
	if (details > 0)
	{
		for(std::map<std::string,std::string>::const_iterator it = m_xpath_map.begin(); it != m_xpath_map.end(); ++it)
		{
			fprintf(fp, "Config XPath: \"%s\" = \"%s\"\n", it->first.c_str(), it->second.c_str());
		}
		for(std::map<std::string,bool>::const_iterator it = m_xpath_bool_map.begin(); it != m_xpath_bool_map.end(); ++it)
		{
			fprintf(fp, "Config XPath: \"%s\" = %s\n", it->first.c_str(), (it->second ? "true" : "false") );
		}
	}
}
void lvDCOMInterface::stopVis(bool only_ones_we_started)
{
	for(vi_map_t::const_iterator it = m_vimap.begin(); it != m_vimap.end(); ++it)
	{
		LabVIEW::VirtualInstrumentPtr vi_ref = it->second.vi_ref;
		if ( (!only_ones_we_started || it->second.started) && (vi_ref != NULL) )
		{
			if (vi_ref->ExecState != LabVIEW::eIdle) // don't try to stop it if it is already stopped
			{
				std::cerr << "stopping \"" << CW2CT(it->first.c_str()) << "\" as it was auto-started and is still running" << std::endl;
				try
				{
					vi_ref->Abort();
				}
				catch(const std::exception& ex)
				{
					std::cerr << "error stopping vi: " << ex.what() << std::endl;
				}
				catch(...)  
				{ 
					std::cerr << "error stopping vi: unknown" << std::endl;
				}
			}
		}
	}
}
// return "" if no value at path
std::string lvDCOMInterface::doXPATH(const std::string& xpath)
{
	if (m_pxmldom == NULL)
	{
		throw std::runtime_error("m_pxmldom is NULL");
	}
	epicsGuard<epicsMutex> _lock(m_lock);
	std::map<std::string,std::string>::const_iterator it = m_xpath_map.find(xpath);
	if (it != m_xpath_map.end())
	{
		return it->second;
	}
	IXMLDOMNode *pNode = NULL;
	std::string S_res;
	BSTR bstrValue = NULL;
	HRESULT hr = m_pxmldom->selectSingleNode(_bstr_t(xpath.c_str()), &pNode);
	if (SUCCEEDED(hr) && pNode != NULL)
	{
		hr=pNode->get_text(&bstrValue);
		if (SUCCEEDED(hr))
		{
			S_res = envExpand(CW2CT(bstrValue));
			SysFreeString(bstrValue);
		}
		pNode->Release();
	}
	//	else
	//	{
	//		throw std::runtime_error("doXPATH: cannot find " + xpath);
	//	}
	m_xpath_map[xpath] = S_res;
	return S_res;
}
Beispiel #5
0
void DumpAce(CSid& sid,
			 ACCESS_MASK mask,
			 BYTE type,
			 BYTE flags,
			 GUID guidObjectType,
			 GUID guidInheritedObjectType,
			 Mapping* pAccessMappings)
{
	CIndent scope;

	Log(_T("Sid:"));
	DumpSid(sid);

	Log(_T("Mask:"));
	DumpAccessMask(mask, pAccessMappings);

	Log(_T("Type:"));
	DumpAceType(type);

	Log(_T("Flags:"));
	DumpAceFlags(flags);

	if (!InlineIsEqualGUID(GUID_NULL, guidObjectType))
	{
		Log(_T("Object Type:"));

		CStringW str;
		if (StringFromGUID2(guidObjectType, CStrBufW(str, 128), 128))
			Log(CW2CT(str));
		else
			Log(_T("Failure converting GUID to String"));
	}

	if (!InlineIsEqualGUID(GUID_NULL, guidInheritedObjectType))
	{
		Log(_T("Inherited Object Type:"));

		CStringW str;
		if (StringFromGUID2(guidInheritedObjectType, CStrBufW(str, 128), 128))
			Log(CW2CT(str));
		else
			Log(_T("Failure converting GUID to String"));
	}
}
BOOL DownloadWebPagePostW(std::string& page, HINTERNET hInternet, LPCWSTR url, LPCSTR postData)
{
	TRACEST(_T("DownloadWebPagePostW"), CW2CT(url));
	BOOL bRet = FALSE;
	URL_COMPONENTSW comp;
	memset(&comp, 0, sizeof(URL_COMPONENTSW));
	comp.dwStructSize = sizeof(URL_COMPONENTSW);
	WCHAR hostName[100], URI[100];
	comp.dwHostNameLength = comp.dwUrlPathLength = 100;
	comp.lpszHostName = hostName;
	comp.lpszUrlPath = URI;
	if (InternetCrackUrlW(url, 0, ICU_ESCAPE, &comp))
	{
		HINTERNET hConnection = InternetConnectW(hInternet, 
			comp.lpszHostName, 
			comp.nPort, 
			NULL, 
			NULL, 
			INTERNET_SERVICE_HTTP, 
			INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_NO_CACHE_WRITE, 
			0);
		if (hConnection)
		{
			LPCTSTR sAcceptTypes[] = {L"*/*",NULL};
			HINTERNET hRequest=::HttpOpenRequestW(hConnection,
				L"POST", // HTTP Verb
				comp.lpszUrlPath, // Object Name
				HTTP_VERSION, // Version
				NULL, // Reference
				sAcceptTypes, // Accept Type
				INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_FORMS_SUBMIT,
				0); // context call-back point
			if(hRequest)
			{
				static LPCWSTR sHttpAccept = L"Accept: */*\r\n";
				::HttpAddRequestHeadersW(hRequest, sHttpAccept, (DWORD)wcslen(sHttpAccept), HTTP_ADDREQ_FLAG_ADD_IF_NEW);

				static LPCWSTR szContentType = L"Content-Type: application/x-www-form-urlencoded\r\n";
				if(::HttpSendRequestW(hRequest,	szContentType, (DWORD)wcslen(szContentType), (LPVOID)postData, (DWORD)strlen(postData)))
					bRet = ReadInternetFile2StringW(hRequest, page);
				else
					HandleInternetError(_T("DownloadWebPagePostW. HttpSendRequestW"));
				InternetCloseHandle(hRequest);
			}
			else
				HandleInternetError(_T("DownloadWebPagePostW. InternetConnectW"));
			InternetCloseHandle(hConnection);
		}
		else
			HandleInternetError(_T("DownloadWebPagePostW. InternetConnectW"));
	}
	else
		HandleInternetError(_T("DownloadWebPagePostW. InternetCrackUrlW"));
	return bRet;
}
Beispiel #7
0
void SimpleBrowser::OnBeforeNavigate2(LPDISPATCH lpDisp, VARIANT FAR *URL,
					   VARIANT FAR *Flags, VARIANT FAR *TargetFrameName,
					   VARIANT FAR *PostData, VARIANT FAR *Headers,
					   VARIANT_BOOL *Cancel)
{
	if (m_pNotifier)
	{
		m_pNotifier->OnBeforeNavigate(CW2CT(URL->bstrVal));
	}

}
LRESULT CAskSendFullDumpDlg::OnLinkClicked(int windowId, LPNMHDR wParam, BOOL& bHandled)
{
    ENLINK* enLink = (ENLINK*) wParam;
    if (enLink->msg != WM_LBUTTONUP)
        return 0;

    if (!m_url.IsEmpty())
        ShellExecute(NULL, _T("open"), CW2CT(m_url), NULL, NULL, SW_SHOWNORMAL);

    bHandled = TRUE;

    return 0;
}
bool lvDCOMInterface::doXPATHbool(const std::string& xpath)
{
	if (m_pxmldom == NULL)
	{
		throw std::runtime_error("m_pxmldom is NULL");
	}
	epicsGuard<epicsMutex> _lock(m_lock);
	std::map<std::string,bool>::const_iterator it = m_xpath_bool_map.find(xpath);
	if (it != m_xpath_bool_map.end())
	{
		return it->second;
	}
	IXMLDOMNode *pNode = NULL;
	bool res = false;
	BSTR bstrValue = NULL;
	std::string bool_str;
	HRESULT hr = m_pxmldom->selectSingleNode(_bstr_t(xpath.c_str()), &pNode);
	if (SUCCEEDED(hr) && pNode != NULL)
	{
		hr=pNode->get_text(&bstrValue);
		if (SUCCEEDED(hr))
		{
			bool_str = envExpand(CW2CT(bstrValue));
			if (bool_str.size() == 0)
			{
				res = false;
			}
			// allow true / yes / non_zero_number
			// note: atol() returns 0 for non numeric strings, so OK in a test for "true"
			else if ( (bool_str[0] == 't') || (bool_str[0] == 'T') || (bool_str[0] == 'y') || (bool_str[0] == 'Y') || (atol(bool_str.c_str()) != 0) )
			{
				res = true;
			}
			else
			{
				res = false;
			}
			SysFreeString(bstrValue);
		}
		pNode->Release();
	}
	//	else
	//	{
	//		throw std::runtime_error("doXPATHbool: cannot find " + xpath);
	//	}
	m_xpath_bool_map[xpath] = res;
	return res;
}
BOOL DownloadWebPageW(std::string& page, HINTERNET hInternet, LPCWSTR url)
{
	TRACEST(_T("DownloadWebPageW"), CW2CT(url));
	BOOL bDownloadSuccess = FALSE;
	if (hInternet == NULL)
		return FALSE;
	HINTERNET hFile = InternetOpenUrlW(hInternet, url, NULL, 0, INTERNET_FLAG_NO_CACHE_WRITE, 0);
	if (hFile)
	{   
		bDownloadSuccess = ReadInternetFile2StringW(hFile, page);
		InternetCloseHandle(hFile);
	}
	else
		HandleInternetError(_T("DownloadWebPage. InternetOpenUrlW"));
	return bDownloadSuccess;
}
BOOL DownloadToFile(LPCTSTR fileName, HINTERNET hInternet, LPCWSTR url)
{
	TRACEST(_T("DownloadToFile"), CW2CT(url));
	BOOL bDownloadSuccess = FALSE;
	if (hInternet == NULL)
		return FALSE;
	HINTERNET hFile = InternetOpenUrl(hInternet, url, NULL, 0, INTERNET_FLAG_NO_CACHE_WRITE, 0);
	if (hFile)
	{   
		const int bufferSize = 8192;
		BYTE bf[bufferSize];
		unsigned long nSize = 0;
		BOOL bReadSuccess = TRUE;
		HANDLE f = CreateFile(fileName, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
		if (f != INVALID_HANDLE_VALUE)
		{
			while(bReadSuccess)
			{
				bReadSuccess = InternetReadFile(hFile, bf, bufferSize, &nSize);
				if (bReadSuccess)
				{
					if (nSize == 0)
					{
						TRACE(_T("@3 DownloadToFile. InternetReadFile Finished\r\n"));
						bDownloadSuccess = TRUE;
						break;
					}
					DWORD bWritten = 0;
					if (WriteFile(f, bf, nSize, &bWritten, NULL) == 0)
					{
						bReadSuccess = FALSE;
						TRACE(_T("@3 DownloadToFile. WriteFile Failed [%d]\r\n"), GetLastError());
					}
				}
				else
					HandleInternetError(_T("DownloadToFile. InternetReadFile"));
			}
			CloseHandle(f);
		}
		else
			TRACE(_T("@3 DownloadToFile. CreateFile Failed [%d]\r\n"), GetLastError());
		InternetCloseHandle(hFile);
	}
	else
		HandleInternetError(_T("DownloadToFile. InternetOpenUrl"));
	return bDownloadSuccess;
}
BOOL DownloadWebPageUnicode(std::wstring& page, HINTERNET hInternet, LPCWSTR url)
{
	TRACEST(_T("DownloadWebPageUnicode"), CW2CT(url));
	BOOL bDownloadSuccess = FALSE;
	if (hInternet == NULL)
		return FALSE;
	HINTERNET hFile = InternetOpenUrl(hInternet, url, NULL, 0, INTERNET_FLAG_NO_CACHE_WRITE, 0);
	if (hFile)
	{   
		page.clear();
		DWORD dwSize = 0;
		INT headerCP = 0;//Latin1
		INT pageCP = 0;//Latin1
		INT workingCP = 1252;//Latin1
		if(!HttpQueryInfo(hFile, HTTP_QUERY_RAW_HEADERS_CRLF, 0, &dwSize, 0))
		{
			if (GetLastError()==ERROR_INSUFFICIENT_BUFFER)
			{
				SetLastError(0);
				LPVOID lpOutBuffer = new CHAR[dwSize];
				if (HttpQueryInfo(hFile, HTTP_QUERY_RAW_HEADERS_CRLF, lpOutBuffer, &dwSize, 0))
				{
					//TRACE((LPCTSTR)lpOutBuffer);
					headerCP = GetWindowsCodePageW((LPCTSTR)lpOutBuffer);
				}
				delete[] lpOutBuffer;
			}		
		}

		DWORD pageSize = 0;
		DWORD pageSizeLen = sizeof(pageSize);
		if (::HttpQueryInfo(hFile, HTTP_QUERY_CONTENT_LENGTH, &pageSize, &pageSizeLen, NULL))
		{
			if (pageSize > 0)
				page.reserve(pageSize + 10);
		}
		if (page.capacity() < 1000)
			page.reserve(50000);
		const int bufferSize = 8192;
		const int bufferSizeU = 2 * bufferSize;
		CHAR bf[bufferSize + 1];
		TCHAR bfU[bufferSizeU];
		unsigned long nSize = 0;
		BOOL bReadSuccess = TRUE;
		BOOL bFirstTime = TRUE;
		while(bReadSuccess)
		{
			bReadSuccess = InternetReadFile(hFile, bf, bufferSize, &nSize);
			if (bReadSuccess)
			{
				if (nSize == 0)
				{
					//TRACE(_T("@3 DownloadWebPage. InternetReadFile Finished\r\n"));
					bDownloadSuccess = TRUE;
					break;
				}
				if (bFirstTime)
				{
					bFirstTime = FALSE;
					bf[nSize] = 0;
					pageCP = GetWindowsCodePageA(bf);
					if (headerCP != pageCP)
					{
						TRACE(_T("@3 DownloadWebPage. CodePage Differs (header:%d - page:%d)\r\n"),
							headerCP, pageCP);
					}
					if (pageCP > 0)	//===Choose the Codepage detected from page if available
						workingCP = pageCP;
					else if (headerCP > 0) //===Else select the Codepage detected from headers if available
						workingCP = headerCP;
					//===Otherwise keep the original 1252 (latin 1)
				}
				if (nSize > 0)
				{
					INT bfLen = MultiByteToWideChar(workingCP, 0, bf, nSize, 0, 0);
					if (bfLen < bufferSizeU)
					{
						MultiByteToWideChar(workingCP, 0, bf, nSize, bfU, bfLen);
						page.append(bfU, bfLen);
					}
					else
					{
						TRACE(_T("@1 DownloadWebPageUnicode. Unicode buffer not enough\r\n"));
						bReadSuccess = FALSE;
					}
				}
			}
			else
				HandleInternetError(_T("DownloadWebPageUnicode. InternetReadFile"));
		}
		InternetCloseHandle(hFile);
	}
	else
		HandleInternetError(_T("DownloadWebPageUnicode. InternetOpenUrl"));
	return bDownloadSuccess;
}
/// \param[in] configSection @copydoc initArg1
/// \param[in] configFile @copydoc initArg2
/// \param[in] host @copydoc initArg3
/// \param[in] options @copydoc initArg4
/// \param[in] progid @copydoc initArg5
/// \param[in] username @copydoc initArg6
/// \param[in] password @copydoc initArg7
lvDCOMInterface::lvDCOMInterface(const char *configSection, const char* configFile, const char* host, int options, const char* progid, const char* username, const char* password) : 
m_configSection(configSection), m_pidentity(NULL), m_pxmldom(NULL), m_options(options), 
	m_progid(progid != NULL? progid : ""), m_username(username != NULL? username : ""), m_password(password != NULL ? password : ""),
	m_mac_env(NULL)
	
{
	epicsThreadOnce(&onceId, initCOM, NULL);
	if (host != NULL && host[0] != '\0') 
	{
		m_host = host;
	}
	else
	{
		//		char name_buffer[MAX_COMPUTERNAME_LENGTH + 1];
		//		DWORD name_size = MAX_COMPUTERNAME_LENGTH + 1;
		//		if ( GetComputerNameEx(ComputerNameNetBIOS, name_buffer, &name_size) != 0 )
		//		{
		//			m_host = name_buffer;
		//		}
		//		else
		//		{
		//			m_host = "localhost";
		//		}			
		m_host = "localhost";
	}
	if (macCreateHandle(&m_mac_env, NULL) != 0)
	{
		throw std::runtime_error("Cannot create mac handle");
	}
	// load current environment into m_mac_env, this is so we can create a macEnvExpand() equivalent 
	// but tied to the environment at a specific time. It is useful if we want to load the same 
	// XML file twice but with a macro defined differently in each case 
	for(char** cp = environ; *cp != NULL; ++cp)
	{
		char* str_tmp = strdup(*cp);
		char* equals_loc = strchr(str_tmp, '='); // split   name=value   string
		if (equals_loc != NULL)
		{
		    *equals_loc = '\0';
		    macPutValue(m_mac_env, str_tmp, equals_loc + 1);
		}
		free(str_tmp);
	}
	//	m_doc = new TiXmlDocument;
	//	if ( !m_doc->LoadFile(configFile) )
	//	{
	//		delete m_doc;
	//		m_doc = NULL;
	//		throw std::runtime_error("Cannot load " + std::string(configFile) + ": load failure");
	//	}
	//	m_root = m_doc->RootElement();
	DomFromCOM();
	short sResult = FALSE;
	char* configFile_expanded = envExpand(configFile);
	m_configFile = configFile_expanded;
	HRESULT hr = m_pxmldom->load(_variant_t(configFile_expanded), &sResult);
	free(configFile_expanded);
	if(FAILED(hr))
	{
		throw std::runtime_error("Cannot load XML \"" + m_configFile + "\" (expanded from \"" + std::string(configFile) + "\"): load failure");
	}
	if (sResult != VARIANT_TRUE)
	{
		throw std::runtime_error("Cannot load XML \"" + m_configFile + "\" (expanded from \"" + std::string(configFile) + "\"): load failure");
	}
	std::cerr << "Loaded XML config file \"" << m_configFile << "\" (expanded from \"" << configFile << "\")" << std::endl;
	m_extint = doPath("/lvinput/extint/@path").c_str();
	epicsAtExit(epicsExitFunc, this);
	if (m_progid.size() > 0)
	{
		if ( CLSIDFromProgID(CT2W(m_progid.c_str()), &m_clsid) != S_OK )
		{
			throw std::runtime_error("Cannot find progId " + m_progid);
		}
	}
	else
	{
		m_clsid = LabVIEW::CLSID_Application;
		wchar_t* progid_str = NULL;
		if ( ProgIDFromCLSID(m_clsid, &progid_str) == S_OK )
		{
			m_progid = CW2CT(progid_str);
			CoTaskMemFree(progid_str);
		}
		else
		{
			m_progid = "LabVIEW.Application";
		}
	}
	wchar_t* clsid_str = NULL;
	if ( StringFromCLSID(m_clsid, &clsid_str) == S_OK )
	{
		std::cerr << "Using ProgID \"" << m_progid << "\" CLSID " << CW2CT(clsid_str) << std::endl;
		CoTaskMemFree(clsid_str);
	}
	else
	{
		std::cerr << "Using ProgID \"" << m_progid << "\" but StringFromCLSID() failed" << std::endl;
	}
}
Beispiel #14
0
void SimpleBrowser::OnTitleChange(BSTR text)
{
	if (m_pNotifier)
		m_pNotifier->OnStatusTextChange(CW2CT(text));
}
Beispiel #15
0
void SimpleBrowser::OnNavigateComplete2(LPDISPATCH lpDisp,VARIANT FAR* URL)
{
	if (m_pNotifier)
		m_pNotifier->OnNavigateComplete(CW2CT(URL->bstrVal));

}
void lvDCOMInterface::createViRef(BSTR vi_name, bool reentrant, LabVIEW::VirtualInstrumentPtr& vi)
{
	epicsThreadOnce(&onceId, initCOM, NULL);
	std::wstring ws(vi_name, SysStringLen(vi_name));
	HRESULT hr;
	if ( (m_lv != NULL) && (m_lv->CheckConnection() == S_OK) )
	{
		;
	}
	else if (m_host.size() > 0)
	{
		std::cerr << "(Re)Making connection to LabVIEW on " << m_host << std::endl;
		CComBSTR host(m_host.c_str());
		m_pidentity = createIdentity(m_username, m_host, m_password);
		COAUTHINFO* pauth = new COAUTHINFO;
		COSERVERINFO csi = { 0, NULL, NULL, 0 };
		pauth->dwAuthnSvc = RPC_C_AUTHN_WINNT;
		pauth->dwAuthnLevel = RPC_C_AUTHN_LEVEL_DEFAULT;
		pauth->dwAuthzSvc = RPC_C_AUTHZ_NONE;
		pauth->dwCapabilities = EOAC_NONE;
		pauth->dwImpersonationLevel = RPC_C_IMP_LEVEL_IMPERSONATE;
		pauth->pAuthIdentityData = m_pidentity;
		pauth->pwszServerPrincName = NULL;
		csi.pwszName = host;
		csi.pAuthInfo = pauth;
		MULTI_QI mq[ 1 ] = { 0 }; 
		mq[ 0 ].pIID = &IID_IDispatch;  // &LabVIEW::DIID__Application; // &IID_IDispatch; 
		mq[ 0 ].pItf = NULL; 
		mq[ 0 ].hr   = S_OK; 
		hr = CoCreateInstanceEx( m_clsid, NULL, CLSCTX_REMOTE_SERVER | CLSCTX_LOCAL_SERVER, &csi, 1, mq ); 
		if( FAILED( hr ) ) 
		{ 
			hr = CoCreateInstanceEx( m_clsid, NULL, CLSCTX_ALL, &csi, 1, mq );
		}
		if( FAILED( hr ) ) 
		{
			throw COMexception("CoCreateInstanceEx (LabVIEW) ", hr);
		} 
		if( S_OK != mq[ 0 ].hr || NULL == mq[ 0 ].pItf ) 
		{ 
			throw COMexception("CoCreateInstanceEx (LabVIEW)(mq) ", mq[ 0 ].hr);
		} 
		setIdentity(m_pidentity, mq[ 0 ].pItf);
		m_lv.Release();
		m_lv.Attach( reinterpret_cast< LabVIEW::_Application* >( mq[ 0 ].pItf ) ); 
		std::cerr << "Successfully connected to LabVIEW on " << m_host << std::endl;
	}
	else
	{
		std::cerr << "(Re)Making local connection to LabVIEW" << std::endl;
		m_pidentity = NULL;
		m_lv.Release();
		hr = m_lv.CoCreateInstance(m_clsid, NULL, CLSCTX_LOCAL_SERVER);
		if( FAILED( hr ) ) 
		{
			throw COMexception("CoCreateInstance (LabVIEW) ", hr);
		} 
		std::cerr << "Successfully connected to local LabVIEW" << std::endl;
	}
	if (reentrant)
	{
		vi = m_lv->GetVIReference(vi_name, "", 1, 8);
		setIdentity(m_pidentity, vi);
	}
	else
	{
		//If a VI is reentrant then always get it as reentrant
		vi = m_lv->GetVIReference(vi_name, "", 0, 0);
		setIdentity(m_pidentity, vi);
		if (vi->IsReentrant)
		{
			vi = m_lv->GetVIReference(vi_name, "", 1, 8);
			setIdentity(m_pidentity, vi);
			reentrant = true;
		}
	}
	ViRef viref(vi, reentrant, false);
	// LabVIEW::ExecStateEnum::eIdle = 1
	// LabVIEW::ExecStateEnum::eRunTopLevel = 2
	if (vi->ExecState == LabVIEW::eIdle)
	{
		if ( checkOption(viStartIfIdle) ) 
		{
			std::cerr << "Starting \"" << CW2CT(vi_name) << "\" on " << (m_host.size() > 0 ? m_host : "localhost") << std::endl;
			vi->Run(true);
			viref.started = true;
		}
		else if ( checkOption(viWarnIfIdle) )
		{
			std::cerr << "\"" << CW2CT(vi_name) << "\" is not running on " << (m_host.size() > 0 ? m_host : "localhost") << " and autostart is disabled" << std::endl;
		}
	}
	m_vimap[ws] = viref;
}
Beispiel #17
0
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPWSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
#if defined(_DEBUG)
	MessageBoxW(NULL, lpCmdLine, L"wait for debug", 0);
#endif
#if !defined(_DEBUG)
	if (lpCmdLine == NULL || lpCmdLine[0] == '\0') {
		//没有任何参数无法运行
		return	0;
	}
#endif
	LOG_FILE(svy::Log::L_INFO,svy::strFormat(_T("run cmd %s"),lpCmdLine));
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);
	//读取自己的配置信息
	svy::SinglePtr<AppModule> app;
	AppModule::REG_INFO regInfo;
	PreLogic			prelogic;	
	app->getMySlefModule();
	prelogic.parseCommondLine();
	if (1 >= app->getModuleCount()) {
		return 0;
	}
	if ( !prelogic.canRunUpdate() ) {
		//建立copy
		CString dirAppD = svy::GetLocalAppDataPath();
		CString dirSrc = svy::GetAppPath();
		CString dirDst = svy::catUrl(dirAppD, svy::GetAppName());
		svy::CopyDir(dirSrc, dirDst);
		//
		dirAppD = dirDst; //缓存运行目录
		dirDst = svy::catUrl(dirDst, svy::GetAppName()) + _T(".exe");
		CString strCmd;
		CString strPrevCmds((LPCTSTR)CW2CT(lpCmdLine));
		strPrevCmds.TrimRight();
		if ('|' != strPrevCmds[strPrevCmds.GetLength() - 1]) {
			strCmd.Format(_T("%s | version:%s %s |"), strPrevCmds,
				app->getMySlefModule().mVer_.mVer_, cmdSelfKey() );
		}
		else {
			strCmd.Format(_T("%s version:%s %s |"), strPrevCmds,
				app->getMySlefModule().mVer_.mVer_, cmdSelfKey() );
		}
		regInfo.path = dirSrc;
		regInfo.name = svy::GetAppName();
		//将自己位置信息写入注册表
		AppModule::SaveRegisteInfo(regInfo);		
		::ShellExecute(NULL, _T("open"), dirDst,strCmd,dirAppD,0);
		return 0;
	}
	//初始化lua模块
	lua_State *L = app->getLua();
	//初始化libcurl环境
	svy::CHttpClient::GlobalSetup();
	//判断是否运行copy
	//访问服务器检查更新
	svy::SinglePtr<UpdateSchedule>	updateSchedule;

	updateSchedule->run();

	svy::CHttpClient::GlobalClean();
	return 0;
}