PHP 4.3.9 / w32api.dl:l StringFromGUID2 doesn't work

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Could somebody tell me what I'm missing here? Constants have been deleted
for brevity:

// Load w32 extension.
if(!dl("php_w32api.dll")) die("No extension");

// Register necessary functions.
$api = new win32;
$api->registerfunction("long GlobalAlloc(long uFlags, long dwBytes) from
$api->registerfunction("long GlobalFree(long hMem) from kernel32.dll");
$api->registerfunction("long CoCreateGuid(long pGuid) from ole32.dll");
$api->registerfunction("int StringFromGUID2(long pGuid, long pOleGuid, int
cchMax) from ole32.dll");
$api->registerfunction("int WideCharToMultiByte(int uCodePage, long dwFlags,
long pMultiByteStr, int cchMulti, string &strAnsi, int cchAnsi) from

// Get a GUID.
$pGuid = $api->GlobalAlloc(GPTR, 16);
$ret = $api->CoCreateGuid($pGuid);
echo "CoCreateGuid returned $ret<br>";

// Convert to OLE string.
$pOleGuid = $api->GlobalAlloc(GPTR, 78);
$ret = $api->StringFromGUID2($pGuid, $pOleGuid, 39);
echo "StringFromGUID2 returned $ret<br>";

// Convert to ANSI string.
$Guid = str_repeat("", 39);
$ret = $api->WideCharToMultiByte(CP_ACP, 0, $pOleGuid, 39, $Guid, 39, 0, 0);
echo "WideCharToMultiByte returned $ret<br>";


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 WideCharToMultiByte 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.

Re: PHP 4.3.9 / w32api.dl:l StringFromGUID2 doesn't work

Quoted text here. Click to load it

Oh GOD what a moron! There are two more parameters to this function.
Nevermind everybody. Shawn needs more caffiene.

Site Timeline