We are trying to use a vendor provided .dll file to extract data from a binary file. Below is sample code and output as well as the vendor’s documentation. The call is supposed to return a Safearray that contains both real and integer values (2 each). What we get back seems to be an array with 23 real values of which seem to match the expected real values in positions 0 and 8 and the first integer at 17 (close should be 2). We are still missing the last integer value (which we need). What is the method to get both real and integer value out of the same Perl array? Thanks.

Brian D. Halligan, Ph.D.

Biotechnology and Bioengineering Center

Medical College of Wisconsin

8701 Watertown Plank Road

Milwaukee, WI 53226

Sample Code:

use Win32::OLE; use Win32::OLE::Variant qw(:DEFAULT nothing); use Data::Dumper; my $filename = $ARGV[0]; Win32::OLE->Option( Warn => 3 ); my $open_raw_file = eval{ Win32::OLE->new('MSFileReader.XRawfile +.1', sub{ $_[0]->Close } ); }; # eval if($@){ warn "Could not create XRawfile object +.$@\nThis function requires Thermo MSFileReader\n"; } # if $open_raw_file->Open($filename); $open_raw_file->SetCurrentController( 0, 1 ); # mass s +pec device, first MS device my $scan_num = 1001; # arbitrary scan number my $arr = Variant( VT_VARIANT | VT_BYREF); my $array_size = Win32::OLE::Variant->new(VT_I4|VT_BYR +EF, 20); $open_raw_file->GetPrecursorInfoFromScanNum($scan_num, + $arr, $array_size); my @values = @{$arr->Value}; print Dumper \@values; print "Array size is $array_size\n"; exit; Output: $VAR1 = [ '414.005279541016', '1.83302424514875e-307', '3.50253979763967e-310', '1.36817960845299e-312', '2.68156223007842e+154', '9.96719496044929e-206', '-7.16479736258273e+154', '1.1404242820188e+279', '414.005218505859', '1.20129076821422e-302', '1.74092514125002e-309', '6.80048883300789e-312', '2.65644095020843e-314', '-4.09173827895217e+149', '4.97033753286898e-290', '5.38341844184884e-309', '2.10289782884708e-311', '2.00000738352537', '7.64529567303078e-298', '2.34086864460609e-289', '5.57490734202886e-309', '4.95144931563519e+173', '5.83291545534861e-302', '4.11480344154759e-270' ]; Array size is 1 Vendor Documentation: GetPrecursorInfoFromScanNum HRESULT GetPrecursorInfoFromScanNum(lo +ng nScanNumber, VARIANT* pvarPrecursorInfos, LONG* pnArraySize) Return Value 0 if successful; otherwise, see Error +Codes. Parameters nScanNumber The scan number for which +the corresponding precursor info is to be returned. pvarPrecursorInfos A valid pointer to +a VARIANT variable to receive the precursor info. pnArraySize A valid pointer to a long +variable to receive the number of precursor info packets returned in the precursor info array. Remarks This function is used to retrieve info +rmation about the parent scans of a data dependent MSn scan. You will retrieve the scan number of t +he parent scan, the isolation mass used, the charge state and the monoisotopic mass as determined by the + instrument firmware. You will also get access to the scan data of the parent scan in the form of a XS +pectrumRead object. For the charge state and the monoisoto +pic mass it is tried to further refine these values from the actual parent scan data. Example struct PrecursorInfo { double dIsolationMass; double dMonoIsoMass; long nChargeState; long nScanNumber; }; void CTestOCXDlg::OnOpenParentScansOcx +() { try { VARIANT vPrecursorInfos; VariantInit(&vPrecursorInfos); long nPrecursorInfos = 0; // Get the precursor scan information 2 Function Reference GetPrecursorInfoFromScanNum Thermo Scientific MSFileReader User Gu +ide (XRawfile2.dll) 197 m_Rawfile.GetPrecursorInfoFromScanNum( +m_nScanNumber, &vPrecursorInfos, &nPrecursorInfos); // Access the safearray buffer BYTE* pData; SafeArrayAccessData(vPrecursorInfos.pa +rray, (void**)&pData); for (int i=0; i < nPrecursorInfos; ++i +) { // Copy the scan infor +mation from the safearray buffer PrecursorInfo info; memcpy(&info, pData + i * sizeof(MS_ +PrecursorInfo), sizeof(PrecursorInfo)) +; // Process the paraent + scan information ... } SafeArrayUnaccessData(vPrecursorInfos. +parray); } catch (...) { AfxMessageBox(_T("Ther +e was a problem while getting the parent scan information.")); }

In reply to Getting mixed real and integer data out of Win32::OLE Safearray by Halligan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.