473,545 Members | 2,543 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hooking server DLL into PHP

We have a RPC based client/server hosting system (Wildcat!). Various RPC
clients include FTP, TELNET, DIALUP as well as WEB server. Each use a
RPC SDK/API to communicate with the central RPC server to establish context
and user sessions.

A few years back (before PHP 4.0) a former employee very familiar with PHP
began to add PHP server side support and wrote a "PHP Module?" to support
PHP 3.0 to expose the SDK API to PHP scripts.

It was never finished (not all the functions were exposed) and although it
was unofficially release to some PHP developers, for some reason or another
it no longer worked with PHP 4.0. We have been asked to update the DLL for
PHP 4.0/5.0.

Unfortunately, the C/C++ source code for the 3.0 version of the DLL was lost
or misplaced.

I believe I got all the information from the PHP support sites, but it
wasn't too obvious to me how to re-engineer the work.

I would like to get the basic skinny on writing a support DLL module to
expose our library of server functions.

Here are some example C/C++ functions and most primitive requirements for a
server-side applet to establish thread context:

BOOL WINAPI wcConnect(const char *szServerName=" ");
BOOL WINAPI wcCreateContext ();
BOOL WINAPI wcCreateContext ByChallenge(con st char *szChalllege);
BOOL WINAPI wcDeleteContext ();

I'm not a PHP script programming expert, but I see a script like so:

<?PHP
// establish context

$challenge = getenv("WILDCAT CONTEXT");
if (!wcCreateConte xtByChallenge($ challenge)) {
echo "Error creating context";
end??
}

... use other API functions ....
wcDeleteContext ();
?>

I appreciate any guidance you may provide to assist in getting this PHP
4.0/5.0 wildcat DLL module written.

Thanks in advance

-- Hector

Jul 17 '05 #1
10 2630
The PHP manual has a section on creating your own extensions:
http://www.php.net/manual/en/zend.php

Jul 17 '05 #2
I was hoping to snap my fingers to get this done. It would be easier of
the provided Window projects file actually compiled the first time.

I guess its time to roll up the sleeves to figure it out. :-)

Thanks. I appreciate the time you took to respond.
<ch***********@ hotmail.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
The PHP manual has a section on creating your own extensions:
http://www.php.net/manual/en/zend.php


Jul 17 '05 #3
The is a PHP extension cakked win32 that lets you call functions in DLL
directly from PHP code. If's not terribly reliable however. PHP also
can also chandle COM objects. Creating an automation interface is not
trivial though; and COM trhouhg PHP like rather flakey. You will like
spend less time writing the wrapper via the standard extension
mechanism.

Jul 17 '05 #4
Thanks for the info.

I was able to finally get ZEND interface/wrapper to work. It was really
much easier than the spread out documentation makes it out to be. It can be
clearer. Of course, once someone knows a system, its all obvious. :-)
Mostly stuff people already encountered and mostly resolved with a google
search. Maybe if I can get the time I can contribute a neat summary layout
for C/C++ Windows developers.

My next step is handle API functions with structures. Once I have atleast
one function worked out as far as what needs to be done to interface a
structure with PHP, I can then write a write a C/C++ converter to a PHP
class like we have for other native languages:

CPP2VB (visual basic
CPP2PAS (delphi pascal)
CPP2VFP (visual foxpro)
CPP2JAVA (java)
CPP2PHP (php)

etc.

I also want to study the "session" stuff to see if we can better interface
with it. Wildcat! is an intranet. Exclusive for login systems only. So its
API automatically establishes sessions context for its inherit server side
WCX p-code engine which is based on a BASIC like compiled language. So when
a WCX script runs it inherits globals a User stricture, Msg structure, File
structures, ConnectionInfo structure, etc. I want to see if I can interface
these globals with PHP as well. It looks like I can with a ZEND GLOBAL
macro, if that want it means.

Anyway, thanks.

--
Hector Santos, Santronics Software, Inc.
http://www.santronics.com
<ch***********@ hotmail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
The is a PHP extension cakked win32 that lets you call functions in DLL
directly from PHP code. If's not terribly reliable however. PHP also
can also chandle COM objects. Creating an automation interface is not
trivial though; and COM trhouhg PHP like rather flakey. You will like
spend less time writing the wrapper via the standard extension
mechanism.


Jul 17 '05 #5
Maybe you can tell me this, because it isn't quite clear in the docs and I
have yet to find an example.

If I have a API function with a pointer to a structure:

BOOL WINAPI foobar(Tfoobar &foo);

How does a PHP SCRIPT create the TFooBar structure? Is there a "Type"
keyword in PHP?

I am looking at the PHP source EXT folder with all the various modules and I
do see some that are using structures, but I don't see how it is used via a
PHP script.
Thanks

<ch***********@ hotmail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
The is a PHP extension cakked win32 that lets you call functions in DLL
directly from PHP code. If's not terribly reliable however. PHP also
can also chandle COM objects. Creating an automation interface is not
trivial though; and COM trhouhg PHP like rather flakey. You will like
spend less time writing the wrapper via the standard extension
mechanism.


Jul 17 '05 #6
PHP classes/structs are hash tables. The wrapper has to rebuild the
structure by searching the table and filling in the elements.
Unfortunately the manual doesn't say much on this topic. The function
you need is zend_hash_find( ) if I remember correctly.

Jul 17 '05 #7

<ch***********@ hotmail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
PHP classes/structs are hash tables. The wrapper has to rebuild the
structure by searching the table and filling in the elements.
Unfortunately the manual doesn't say much on this topic. The function
you need is zend_hash_find( ) if I remember correctly.


Ok, I kinda of saw this. Wasn't sure if this was the only method. Thanks
for clarifying it.

think I can really fly with this if I can see an example PHP script, lets
say for a simple typedef example:

typedef struct _TFooBar {
BOOL fBoolean;
int iNumber;
char szString[256];
} TFooBar;

What is the PHP script for this? Whats the interface like?

Do I have to expose each field as a Function "Get/Put" like method?

--
Hector Santos, Santronics Software, Inc.
http://www.santronics.com

Jul 17 '05 #8
You would do something like this:

PHP_FUNCTION(so me_func)
{
zval *obj, *elem;
TFooBar foo;

zend_parse_para meters(ZEND_NUM _ARGS() TSRMLS_CC, "o", &obj);

zend_hash_find( foo, "fBoolean", &elem);
foo.fBoolean = ZVAL_BOOL(elem) ;

zend_hash_find( foo, "iNumber", &elem);
foo.iNumber = ZVAL_BOOL(elem) ;

}

Basically, you need to crack the structure yourself. They might have
some funky macros that does it for you though. Google around and maybe
look through some of the header files.

Jul 17 '05 #9
The DLL module side I think I got a relatively good handle (because there
are plenty of EXT module examples).

It is the PHP script side that I can't see right now. Like would be the PHP
script to use this function some_func() with a structure?

Something like this?

<?PHP

class TFooBar {
var $boo_field;
var $num_field;
var $string_field:
};

$foobar = new(TFoobar);
if (!some_func($fo obar)) {
echo "error with function";
exit;
}

echo "Success!";

?>

I did a search (PHP Script passing structure and other various keywords) and
couldn't see anything specifically in this area.

What do you mean by "crack?" I am not familar with that term in this regard.

Thanks

--
Hector Santos, Santronics Software, Inc.
http://www.santronics.com
<ch***********@ hotmail.com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
You would do something like this:

PHP_FUNCTION(so me_func)
{
zval *obj, *elem;
TFooBar foo;

zend_parse_para meters(ZEND_NUM _ARGS() TSRMLS_CC, "o", &obj);

zend_hash_find( foo, "fBoolean", &elem);
foo.fBoolean = ZVAL_BOOL(elem) ;

zend_hash_find( foo, "iNumber", &elem);
foo.iNumber = ZVAL_BOOL(elem) ;

}

Basically, you need to crack the structure yourself. They might have
some funky macros that does it for you though. Google around and maybe
look through some of the header files.


Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
1378
by: (Pete Cresswell) | last post by:
I'm about to start climbing the .Net learning curve. Would like to start by reproducing a little application that I already have up and running using an MS Access front end. It manages information for class reunions. Seems to have the basics: parent/child records, "Find" functionality, Add/Change/Delete functionality.... However I...
1
5342
by: Matthew Kelly | last post by:
I have pulled together a VB.net project that hooks the keyboard (Ref. Paul Kimmel's hooking program) and allow the user to send "mouse right clicks" via the SendInpuut function (mouse emulation works fine). I am also trying to make this project capable of "Rearrange the keyboard" (example type "e" and "K" is sent to the application) by using...
79
5204
by: pinkfloydhomer | last post by:
I want to scan a file byte for byte for occurences of the the four byte pattern 0x00000100. I've tried with this: # start import sys numChars = 0 startCode = 0 count = 0
3
4473
by: Rick Strahl [MVP] | last post by:
I'm working on an app that's using the WebBrowser control. I got the control working fine, hooking to the document object. But I've run into a major issue with hooking the Document events. Whenever I hook any of the HTMLDocumnetEvent2_Event events like this: HTMLDocumentEvents2_Event DocEvents = this.Browser.Document as...
2
1118
by: Brian Bender | last post by:
I am trying to write a static utility class that allows me to modify Application variables in my web application. My problem is that I cannot figure out what to import or inherit to allow me to see application objects or even the server object. Here is my code: Public Shared RefreshCachedXMLDatasets()
2
3014
by: Dave A | last post by:
I am stuggling with databinding a drop down list, hooking into the SelectedIndexChanged and attempting to avoid using the viewstate. The drop down list is quite large so I would prefer to avoid using the view state so I set EnableViewState on the page to false. To enable the drop down list to bind to a datasource I bind it during the OnInit. ...
5
2008
by: Ryan Ginstrom | last post by:
Apropos recent threads about GUI editors, coming from a Win32/WTL C++ background, I actually like the idea of being able to (easily) create GUIs programmatically. But I still see a lot of the same tedium: hooking up events to handlers, and getting data into and out of dialogs. In C++, this is generally handled through code generation and/or...
8
1955
by: pigeonrandle | last post by:
Hi, Has anyone had any experience with hooking messages in other application windows (like SPY++). I want to listen for WM_MOVE messages, but can only seem to find examples of Keyboard and Mouse hooks. Please (and thankyou), James Randle.
0
3729
by: joemango | last post by:
Hi everyone, I was just reading the following artilce titled: "Spy: A Windows CE API Interceptor" by Dmitri Leman in Dr. Dobbs Journal, September 02, 2003 located at http://www.ddj.com/184405459?pgno=1 the article presents source code that includes a dll file which holds all the hooking procedures it is written in C++. Is there an...
1
7413
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7751
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5323
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3449
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3440
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1874
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
700
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.