For Programmers: Free Programming Magazines  


Home > Archive > APL > January 2007 > Re: Help request about using WCALL in APL+Win to call a C++ DLL









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Help request about using WCALL in APL+Win to call a C++ DLL
Tracker

2007-01-17, 6:57 pm

Vess - here is my guess - APL+Win is interpreting the name of the function OK, i.e., 'aa'. But there is another character string in the RARG that is not getting interpreted correctly. APL+Win will look for other character strings in []WCALL and do const
ant substitutions for example. So I would look at your RARG to be sure it is constructed correctly, and for perhaps character scalar that should be a one element vector. So, what does your RARG look like? And definitely get rid of the C++ decorations!
<g>



Vess Irvine wrote:
> Hi APLers the world over:
>
> Sorry if I duplicate this posting. I think my computer clock sent the first
> message out with a back date from last summer. Why is my computer clock so
> wrong, you ask? Good question.
>
> For the below examples the APL is APL+Win Version 4.0 from APL2000, Inc. and
> the C++ compiler (that mangles the names below) is from Microsoft Visual
> Studio 6.0 C++ 6.0.
>
> I am getting this error message when I try to call a self-written C++ DLL.
>
> BACKfromADCO5 <= []WCALL (Enclose 'aa'),RARG
> []WCALL ARGUMENT ERROR: Function name must be character vector
>
> Now 'aa' is certainly a character vector in the above statement. My C++ DLL
> function prototype in the APLW.ADF file is .....
>
> [Call]
>
> ? adco_version_5p1@@YAJQAD0J0JQAY0HJ@NJQAY
0HJ@JJQAY113J0JQAY11P@JQAN@Z=L(>C
> version_v5, >C errmsg_v5, L n_cycles_v5, *C which_model, L cols_dbl_v5, >E
> dbl_v5, L cols_int_v5, >L int_v5, L cols_string_v5, *L inc_ptr_string_v5, >C
> string_v5, L cols_timeseries_v5, *L inc_ptr_timeseries_v5, >E timeseries_v5)
> LIB natoadco5.dll
>
> aa=L(>C version_v5, >C errmsg_v5, L n_cycles_v5, *C which_model, L
> cols_dbl_v5, >E dbl_v5, L cols_int_v5, >L int_v5, L cols_string_v5, *L
> inc_ptr_string_v5, >C string_v5, L cols_timeseries_v5, *L
> inc_ptr_timeseries_v5, >E timeseries_v5) ALIAS
> ? adco_version_5p1@@YAJQAD0J0JQAY0HJ@NJQAY
0HJ@JJQAY113J0JQAY11P@JQAN@Z LIB
> natoadco5.dll
>
> ...... and you see the "aa" is an ALIAS for a very long C++ compiler mangled
> name of a function in my dll .....
>
> ? adco_version_5p1@@YAJQAD0J0JQAY0HJ@NJQAY
0HJ@JJQAY113J0JQAY11P@JQAN@Z
>
> .... the function name in the C++ source code is ...... adco_version_5p1.
> Microsoft adds all the mangling to the name.
>
> I have had trouble with long mangled C++ names using the APL function []NA.
> Shorter names, even if mangled, say 1/3rd the length as above, do work with
> []NA and with []WCALL, as well as I can tell. I discovered this fact by
> trial and error back in 2004.
>
> Note in the prototypes there are 14 arguments to the C++ DLL function call
>
> If I mess up the right argument (RARG) to []WCALL, by making it something
> other then 14 variables long, you see a different error message that
> indicates that APL is indeed reading the function protoype information
> through the ALIAS name 'aa'
>
> BACKfromADCO5 <= []WCALL (Enclose 'aa'), 2 rho RARG
> []WCALL CALL ERROR: Wrong number of arguments
>
> BACKfromADCO5 <= []WCALL (Enclose 'aa'), 15 rho RARG
> []WCALL CALL ERROR: Wrong number of arguments
>
>
> ..... but an argument of 14 (correct length) elements long does return us to
> the original error message ......
>
> BACKfromADCO5 <= []WCALL (Enclose 'aa'), 14 rho RARG
> []WCALL ARGUMENT ERROR: Function name must be character vector
>
>
> ..... and if I intentionally miss type the argument as 'aaa' instead of 'aa'
> ......
>
> BACKfromADCO5 <= []WCALL (Enclose 'aaa'),14 rho RARG
> []WCALL COMMAND ERROR: Undefined function: aaa
>
> ...... which proves that []WCALL is reading the function name as a character
> vector
>
> Any help will be very appreciated. I am stuck. Thanks.
>
> Vess Irvine
> Buffaloed in Estes Park, Colorado
>
> PS If you also know how to make C++ mangle to shorter names, perhaps through
> some compiler option or such, that would be helpful as well.
>
> PPS The third party software I am working with is the Andrew Davidson & Co.
> (ADCO, NYC) mortgage prepayment model. I wrote my DLL as a bridge between
> APL+Win and the ADCO DLL.
>
> If any of you are into Wall Street analytics; say in mortgage backed
> securities, and want to interface ADCO with APL, give me a jingle. By
> default, I think I am the world's expert on this nitch knowledge.
>
>

Tracker

2007-01-17, 6:57 pm

racker wrote:
> Vess - here is my guess - APL+Win is interpreting the name of the
> function OK, i.e., 'aa'. But there is another character string in the
> RARG that is not getting interpreted correctly. APL+Win will look for
> other character strings in []WCALL and do constant substitutions for
> example. So I would look at your RARG to be sure it is constructed
> correctly, and for perhaps character scalar that should be a one element
> vector. So, what does your RARG look like? And definitely get rid of
> the C++ decorations! <g>
>


Then again - I'm probably wrong. I did a test using a constant value I know is not in my ADF file, and APL reports the appropriate error. 'MOD_WIN' is not defined, and sure enough, APL traps it correctly.

[]WCALL CONSTANT ERROR: Identifier not found, "MOD_WIN"
[]wcall 'RegisterHotKey' ('fmHotKey' []wi 'hwnd') 100 'MOD_WIN' 'Y'
^
Vess Irvine

2007-01-18, 3:57 am

Hi Tracker:

The right argument is passing a ton of parameters to the Andrew Davidson
Mortgage Prepayment Model, about 200 "longs" and "doubles," three different
character string inputs (which t-bill curves to use, which data library to
use. etc.), a half dozen floating timeseries (t-bill yield curves,
forecasted ARM rate adjustments, etc.); for each Monte Carlo scenario, of
which there may be 100 scenarios.

It also passes a bunch of -9999.9 timeseries as memory for where the ADCO
models put their answers. Finally I pass a couple of "pointer increment"
integer arrays so that I can parse in C++ the massive double vector variable
(RARG[14]) into individual timeseries.

rho RARG
14
]DISPLAY rho each RARG
|| 256 || 256 || 1 || 7 || 0 || 7 121 || 0 || 7 121 || 0 || 7 2 4 || 316 ||
0 || 7 2 16 || 4654 ||

]DISPLAY rho each rho each RARG
|| 1 || 1 || 1 || 1 || 0 || 2 || 0 || 2 || 0 || 3 || 1 || 0 || 3 || 1 ||

[]DR each RARG
82 82 323 82 323 645 323 323 323 323 82 323 323 645

ADCO is totally C++ and OOP. The ADCO SDK arrives as a DLL, some C++ source
code examples, some .H files and a .LIB file. It has "classes" out the you
know what. I am left to figure out the implementation pretty much from the
member function declaration statements. They do have one really good guy
manning the HELP desk.

If you want, google the Andrew Davidson web site to see how many parameters
are in their model. I have approximately 600 hours into this project
(integrating to ADCO), mostly the APL part. My ADCO screens alone in WSMODEL
for Windows have currently 110 input fields. Users will have TOTAL control
over the ADCO model through a classic flexible APL interface that includes,
Look Up Tables, Calculation Tables (in APL, user written if they want to),
Timeseries Tables, Generic Parameter Screens, Screen Default Tables and
Report Generator Tables.

The idea is to give the user the tools to allow WSMODEL for Windows to auto
generate 95% of the parameters (about 600 alone now in the core WSMODEL),
leaving the last 5% to input ASCII files for stuff like loan interest rate,
principal balance, remaining term, etc., for which the user's IT department
must "crack a tape."

I don't want to dip into ADCO for each scenario or sensitivity cycle,
because calc times are primo. So I call ADCO once per loan pool (or
individual loan if loan x loan analysis) and don't come out until all 100
mortgage prepayment timeseries forecasts are finished. Big users like Wells
Fargo and Chase have millions of loans to crunch (x 100 Monte Carlo
scenarios), gads!

Some people have resorted to multiple linked CPUs to multithread the
workload. To me, that sounds like more trouble then it is worth. Make your
base model fast enough and perhaps one screaming PC can do such jobs in 1/2
day. Maybe.

That is why I am not unhappy about having to learn C++. With that knowledge,
I have new avenues to pursue to make my APL model run faster. I have about
tweaked the APL to death over the years to squeeze every ounce of
performance. It does run competitively fast, since I am utilizing parallel
math to the max (one pass through the loan pool math (we call that a
"segment" of the portfolio) for all sensitivity cycles and Monte Carlo
scenarios). Lots of array nesting here and use of the "each" operator! LOL.

Vess Irvine
Estes Park, Colorado
www.wsmodel.com






----- Original Message -----
From: "Tracker" <null@email.net>
Newsgroups: comp.lang.apl
Sent: Wednesday, January 17, 2007 12:27 PM
Subject: Re: Help request about using []WCALL in APL+Win to call a C++ DLL


> Vess - here is my guess - APL+Win is interpreting the name of the function
> OK, i.e., 'aa'. But there is another character string in the RARG that is
> not getting interpreted correctly. APL+Win will look for other character
> strings in []WCALL and do constant substitutions for example. So I would
> look at your RARG to be sure it is constructed correctly, and for perhaps
> character scalar that should be a one element vector. So, what does your
> RARG look like? And definitely get rid of the C++ decorations! <g>
>
>
>
> Vess Irvine wrote:
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com