Could somebody tell me what I'm missing here? Constants have been deleted
for brevity:
// Load w32 extension.
if(!dl("php_w32 api.dll")) die("No extension");
// Register necessary functions.
$api = new win32;
$api->registerfuncti on("long GlobalAlloc(lon g uFlags, long dwBytes) from
kernel32.dll");
$api->registerfuncti on("long GlobalFree(long hMem) from kernel32.dll");
$api->registerfuncti on("long CoCreateGuid(lo ng pGuid) from ole32.dll");
$api->registerfuncti on("int StringFromGUID2 (long pGuid, long pOleGuid, int
cchMax) from ole32.dll");
$api->registerfuncti on("int WideCharToMulti Byte(int uCodePage, long dwFlags,
long pMultiByteStr, int cchMulti, string &strAnsi, int cchAnsi) from
kernel32.dll");
// Get a GUID.
$pGuid = $api->GlobalAlloc(GP TR, 16);
$ret = $api->CoCreateGuid($ pGuid);
echo "CoCreateGu id returned $ret<br>";
// Convert to OLE string.
$pOleGuid = $api->GlobalAlloc(GP TR, 78);
$ret = $api->StringFromGUID 2($pGuid, $pOleGuid, 39);
echo "StringFromGUID 2 returned $ret<br>";
exit();
// Convert to ANSI string.
$Guid = str_repeat("\0" , 39);
$ret = $api->WideCharToMult iByte(CP_ACP, 0, $pOleGuid, 39, $Guid, 39, 0, 0);
echo "WideCharToMult iByte returned $ret<br>";
$api->GlobalFree($pO leGuid);
$api->GlobalFree($pG uid);
echo $Guid;
The call to StringFromGUID2 always fails, returning 0. The ascertation that
the OLESTR is not long enough is *NOT* correct. The exact same code works
fine in C. Furthermore, if the call to WideCharToMulti Byte is allowed to
proceed then php crashes with an access violation. This is not correct
either. A zero-length wide char string converts to a zero-length ANSI str.
According to what applicable documentation I can find this should work fine,
but the documentation is not 4.3.9 specific. Everything works fine until I
start dealing with wide characters.
--
-SHAWN-
for brevity:
// Load w32 extension.
if(!dl("php_w32 api.dll")) die("No extension");
// Register necessary functions.
$api = new win32;
$api->registerfuncti on("long GlobalAlloc(lon g uFlags, long dwBytes) from
kernel32.dll");
$api->registerfuncti on("long GlobalFree(long hMem) from kernel32.dll");
$api->registerfuncti on("long CoCreateGuid(lo ng pGuid) from ole32.dll");
$api->registerfuncti on("int StringFromGUID2 (long pGuid, long pOleGuid, int
cchMax) from ole32.dll");
$api->registerfuncti on("int WideCharToMulti Byte(int uCodePage, long dwFlags,
long pMultiByteStr, int cchMulti, string &strAnsi, int cchAnsi) from
kernel32.dll");
// Get a GUID.
$pGuid = $api->GlobalAlloc(GP TR, 16);
$ret = $api->CoCreateGuid($ pGuid);
echo "CoCreateGu id returned $ret<br>";
// Convert to OLE string.
$pOleGuid = $api->GlobalAlloc(GP TR, 78);
$ret = $api->StringFromGUID 2($pGuid, $pOleGuid, 39);
echo "StringFromGUID 2 returned $ret<br>";
exit();
// Convert to ANSI string.
$Guid = str_repeat("\0" , 39);
$ret = $api->WideCharToMult iByte(CP_ACP, 0, $pOleGuid, 39, $Guid, 39, 0, 0);
echo "WideCharToMult iByte returned $ret<br>";
$api->GlobalFree($pO leGuid);
$api->GlobalFree($pG uid);
echo $Guid;
The call to StringFromGUID2 always fails, returning 0. The ascertation that
the OLESTR is not long enough is *NOT* correct. The exact same code works
fine in C. Furthermore, if the call to WideCharToMulti Byte is allowed to
proceed then php crashes with an access violation. This is not correct
either. A zero-length wide char string converts to a zero-length ANSI str.
According to what applicable documentation I can find this should work fine,
but the documentation is not 4.3.9 specific. Everything works fine until I
start dealing with wide characters.
--
-SHAWN-
Comment