To use the class COM
it is necessary to activate the extension php_com_dotnet.dll
in php.ini (clearly this is only for Windows), something like this:
extension=php_com_dotnet.dll
After this you need to restart Apache/Nginx/lighttpd (or restart the server/machine).
The class new COM
doesn’t have much documentation anyway, because there’s nothing to talk about, this because the only thing he does is release the functions of a Registered DLL in the operating system.
The class does not load or read Dlls, it only loads the registered Dlls functions, as example of some Activex usage.
WITH IT MEANS Component Object Model, ie the class will only access Dlls that use things like OLE, basically if the DLL is not made with OLE and compatible, it will not be possible to use new COM
, as I said this is not a class to load Dlls but to load the Dlls functions registered in the System.
i do not know whether it is possible to access all Activex, COM+ and DCOM, which are other technologies of the same track, I will edit the answer as soon as I can confirm.
To register a Dlls it is necessary to run the command REGSVR32:
REGSVR32 minhadll.dll
If the DLL has the COM interface and the record occurs all right, then you will have access via PHP normally, something like (hypothetical example):
Run DLL by command line
Assuming that the documentation provides some access to a command line tool of the SAT itself, could use a shell_exec
thus:
$comando = escapeshellcmd('ferramenta_sat_hipotetica.exe comando1 comando2 arg3');
$resposta = shell_exec($comando);
echo $resposta;
You can also try running the Windows RUNDLL32 command:
RUNDLL32.EXE <dllname>,<entrypoint> <optional arguments>
It would look something like:
RUNDLL32.EXE MINHADLL.DLL,Install 200 Argumento
In PHP it would look like this:
$comando = escapeshellcmd('RUNDLL.EXE MINHADLL.DLL,Install 200 Argumento');
$resposta = shell_exec($comando);
echo $resposta;
Read more about RUNDLL in:
I found the documentation and an example with the DLL, in the example they put an extra quote, maybe it is typo new COM('"SATscript.DLL.object')
, yet if you fail try this new COM('SATscript.DLL.object')
.
First download the http://sistemas.sweda.com.br/downloads/suporte/SATscript.zip then rotate the REGSATscript.exe
that this inside the compact, it will register the DLL, should run version 64bit if you are using Windows 64bit, any questions or problem inside the folder has this file SATscript.zip\Manual\ManualdoUsuarioSATScript.pdf
, after registering the DLL just run:
<?php
try {
$SATsw = new COM('"SATscript.DLL.object') OR die ('NÃO POSSO CRIAR OBJETO');
// "????????????????? S T A T U S ???????????????????????????"
// "Índice Retorno 0 Retorno 1 "
// " 1 Impressora operacional Impressora em falha"
// " 2 Off Line On Line "
// " 3 Papel OK Fim de papel "
// " 4 Guilhotina não detectada Guilhotina detectada "
// " 5 Tampa térmica fechada Tampa térmica aberta "
// " 6 Sem papel sobre o sensor Papel posicionado sobre o sensor "
// " 7 Gaveta fechada Gaveta aberta. "
// " 8 Cheque inserido SEM CHEQUE."
$LF = '<br>';
$retorno = $SATsw->Status_SI300 ("1");
echo 'Status_SAT ("1") -> Operacional? = ', $retorno, $LF;
$retorno = $SATsw->Status_SI300 ("2");
echo 'Status_SAT ("2") -> ON/OFF? = ', $retorno, $LF;
$retorno = $SATsw->Status_SI300 ("3");
echo 'Status_SAT ("3") -> FIM Papel? = ', $retorno, $LF;
$retorno = $SATsw->Status_SI300 ("4");
echo 'Status_SAT ("4") -> Guilhotina? = ', $retorno, $LF;
$retorno = $SATsw->Status_SI300 ("5");
echo 'Status_SAT ("5") -> Tampa? = ', $retorno, $LF;
$retorno = $SATsw->Status_SI300 ("6");
echo 'Status_SAT ("6") -> Papel acabando? = ', $retorno, $LF;
$retorno = $SATsw->Status_SI300 ("7");
echo 'Status_SAT ("7") -> Gaveta? = ', $retorno, $LF;
$retorno = $SATsw->Status_SI300 ("8");
echo 'Status_SAT ("8") -> Cheque? = ', $retorno, $LF;
$retorno = $SATsw->StatusGuilhotina_SI300 ();
echo 'StatusGuilhotina_SI300 () -> Guilhotina? = ', $retorno, $LF;
} catch (Exception $e) {
echo 'resultado: ', $e->getMessage(), "\n";
}
The
new COM
only releases the functions of the Dlls or port (depends on what you will do), but basically what you need is the documentation of such Dlls and that they have an "activex" (COM server...??) to know the commands and not PHP necessarily.– Guilherme Nascimento
Actually I need to access the functions of this DLL. I have the manual with the functions that the SAT dll offers, but I’m not able to access the dll. I try to access with the class with passing DLL name (new COM(name_da_dl.dl)) but returns the error Fatal error: Uncaught Exception 'com_exception' with message 'Failed to create COM Object'
– Diego Queiroz
A dll is registered (with
REGSVR32
)? Note that according to the PHP documentation, if the DLL does not have support for COM server orIDispatch
then PHP won’t be able to do anything, PHP won’t access Dlls, it accesses DLL COM.– Guilherme Nascimento
Diego that
new COM(nome_da_dl.dl)
does not make sense, COM is to access registered Dlls, are you sure you really read the php doc? I will pass the link and try to formulate a reply, following the doc link: http://php.net/manual/faq.com.php– Guilherme Nascimento
Thank you for your answers, William. The dll is not registered, is provided by Sefaz and do not know if it has support COM or Idispatch, in the manual there is no reference to this. The problem is the lack of examples and documentation to access the functions to communicate with the SAT Emulator in PHP. I’m 2 days researching and nothing :(.
– Diego Queiroz
PHP has no way to document any of this, what it does is to free up access to functions, see if you can understand the answer I posted and try to use the
new COM
and then tells me the error/Exception that occurs exactly– Guilherme Nascimento