php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63164 PHP extension for COM connection
Submitted: 2012-09-26 14:28 UTC Modified: 2012-09-27 09:56 UTC
From: gospodin dot p dot zh at gmail dot com Assigned:
Status: Not a bug Package: COM related
PHP Version: 5.4.7 OS: Windows
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gospodin dot p dot zh at gmail dot com
New email:
PHP Version: OS:

 

 [2012-09-26 14:28 UTC] gospodin dot p dot zh at gmail dot com
Description:
------------
char* Connect1c77(char* dir, char* username, char* password, bool 
no_splash_screen){
	//для начала инициализируем COM
	HRESULT hr = CoInitialize(NULL);
	if(FAILED(hr))
	{
	  return"Невозможно инициализировать COM!";
	  return FALSE;
	}

	CLSID   cls77;

	hr = CLSIDFromProgID(L"V77M.Application", &cls77); 
	if(FAILED(hr))
	{
	  return"Переустановите 1С Предприятие!";
	  CoUninitialize();
	  return FALSE;
	}

	IDispatch *pv77;


	hr = CoCreateInstance(cls77, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, 
(void**)&pv77);

	if(FAILED(hr)  ||  !pv77)
	{
	  return"Невозможно инициализировать интерфейс 1С Предприятия"; 
	  CoUninitialize();
	  return FALSE;
	}


	VARIANT       vRet;
	DISPID dispIDRmTrade, dispIDInitialize;
	DISPPARAMS args = {0, 0, 0, 0};
	VARIANT vars[3];  // Параметры для вызова Initialize


	BSTR rmTrade = L"RMTrade";

	hr = pv77->GetIDsOfNames(IID_NULL, &rmTrade, 1, 0, &dispIDRmTrade);

	if (FAILED(hr))
	{
	  return"Невозможно получить ID от RMTrade";
	  if (pv77)
		pv77->Release();
	  CoUninitialize();
	  return FALSE;
	}

	hr = pv77->Invoke(dispIDRmTrade, IID_NULL, 0, DISPATCH_PROPERTYGET, 
&args,
		  &vars[2], NULL, NULL);

	if (FAILED(hr))
	{
	  return"Невозможно получить интерфейс от RMTrade";
	  if (pv77)
		pv77->Release();
	  CoUninitialize();
	  return FALSE;
	}

	//нужно получить ID для Initialize(..);
	BSTR init = L"Initialize";
	hr = pv77->GetIDsOfNames(IID_NULL, &init, 1, 0, &dispIDInitialize);
	if (FAILED(hr))
	{
	  return"Не удалось получить ID от Initialize";
	  if (pv77)
		pv77->Release();
	  CoUninitialize();
	  return FALSE;
	}


	args.cArgs = 3;
	args.rgvarg = vars;
	std::wstring path = L"/DC:\\Users\\Public\\Documents\\old\\Steklo\\ /Nya 
/P185224";

	vars[0] = _variant_t(no_splash_screen ? L"NO_SPLASH_SHOW" : L""); 
	vars[1] = _variant_t(path.c_str());;


	hr = pv77->Invoke(dispIDInitialize, IID_NULL, 0, DISPATCH_PROPERTYGET, 
&args, 
	   &vRet, NULL, NULL);

	if(FAILED(hr) ||  (vRet.vt ==  VT_BOOL && vRet.bstrVal == 0x00))
	{
	  return"Невозможно запустить 1С Предприятие";
	}

	return "ok";
}

Actual result:
--------------
This code work fine if compiled like Win32 application.
When i make it a part of PHP extension (dll) and call from PHP script started 
program behaves like path 

	std::wstring path = L"/DC:\\Users\\Public\\Documents\\old\\Steklo\\ /Nya 
/P185224";

is incorrect, but there is no any windows or messages of course. Stated program is 
in memory has size like there exists only windows to enter correct path (such 
window is shown if it's a win32 application, not a PHP extension).

Help me somehow please

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-27 08:41 UTC] gospodin dot p dot zh at gmail dot com
i've checked memory dump, seems like strings were additionally processed for 
slashes as escape sequences. Here is print screen  
http://imageshack.us/a/img10/2097/phpu.gif
 [2012-09-27 08:47 UTC] pajoye@php.net
-Status: Open +Status: Not a bug
 [2012-09-27 08:47 UTC] pajoye@php.net
hi!

Please ask support questions about php extension development on the PECL developer 
mailing list.

Btw, why not contribute to the existing COM extension instead?
 [2012-09-27 09:38 UTC] gospodin dot p dot zh at gmail dot com
[2012-09-27 08:47 UTC] pajoye@php.net

i need to store single (only one) instance of COM launched application for all PHP 
session. That's why i've started to write extension. Can you advice me good 
existing COM extension ? May be than i'll will use my self-male extension only to 
store a COM variable.
 [2012-09-27 09:56 UTC] pajoye@php.net
Please let continue this discussion on pecl-dev
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Oct 15 14:01:27 2024 UTC