in reply to calling a function from a dll

http://msdn.microsoft.com/en-us/library/windows/desktop/ms221069%28v=vs.85%29.aspx

A BSTR * is something similar to a char **, but it is NOT a char ** or WCHAR **. If the function wants to realloc, free, or take ownership of the BSTR, it can typically do so by put a NULL in your BSTR * or putting a different BSTR into the BSTR *. I am guessing since you didn't provide any docs on the C function it can take ownership. Win32::OLE has a couple nice looking C SV to BSTR and BSTR to SV functions but they are not exported from the DLL by default. A BSTR comes from a foreign memory allocation, you can't treat a BSTR as a regular string-ish scalar (I am not going to write an overload.pm module that implements BSTRs, sorry). You will probably have to treat it as an integer in Perl, then use Perl XS subs or pack() to read, write, and free it. I don't see anything very difficult here, it is just going to take more code in Perl to do it than in C. Windows OS has way too many memory allocators and string formats. Soon someone will want to use ASCII_STRING and UNICODE_STRING with Win32::API.

TLDR: If your BSTR didn't come from SysAllocString or the like, you will probably crash.