Posted by
Plamen Neykov on
May 18, 2005; 8:03am
URL: http://quantlib.414.s1.nabble.com/Trouble-getting-QuantLibAddin-to-work-with-vc-7-1-tp10802p10808.html
On Wednesday 18 May 2005 15:40, eric ehlers wrote:
> On 5/18/05, Plamen Neykov <
[hidden email]> wrote:
> > Hi Eric,
> >
> > I've took a look where the TempStr function is used - it comes
> > predominantely in the generated code - qladdin.cpp, I found only one
> > reference elsewhere - in the file xlutils.cpp. I think the python
> > generaton procedure could be easily changed in the way to generate in the
> > first byte of a string literal the size of it directly so that this
> > doesn't have to be done run-time - I could try to change it - what do you
> > think?
> >
> > Thanks,
> > Plamen
>
> Hi Plamen,
>
> Here's a revised TempStr function which should do the trick:
>
> LPXLOPER TempStr(LPSTR lpstr)
> {
> LPXLOPER lpx;
>
> lpx = (LPXLOPER) GetTempMemory(sizeof(XLOPER));
>
> if (!lpx)
> {
> return 0;
> }
> /*
> lpstr[0] = (BYTE) lstrlen (lpstr+1);
> lpx->xltype = xltypeStr;
> // lpx->val.str = (PUCHAR) lpstr;
> lpx->val.str = lpstr;
> */
> int len = strlen(lpstr);
> lpx->xltype = xltypeStr;
> lpx->val.str = GetTempMemory(len);
> if (!lpx->val.str) return 0;
> strncpy(lpx->val.str, lpstr, len);
> lpx->val.str[0] = (BYTE) len-1;
>
> return lpx;
> }
>
> But your proposed solution is much preferable:
> - faster
> - no risk of exceeding available temp memory
> - no VC7-specific hack
> so if you're happy to implement that it would be hugely appreciated.
>
> Regards,
> Eric
Hi Eric,
I've done the changes (but still have to test them!). Here the preliminary
changes I've done (I'll send you a proper diff file later on today if the
testing is ok ;-) ):
Addin/excel.py
13c13
< REGLINE = ' TempStrNoSize("%s")%s'
---
> REGLINE = ' TempStr(" %s")%s'
21,22d20
< def generateExcelStringLiteral(str): return '\\x%02X%s'%(len(str),str)
<
56c54
< str1 = REGLINE % (generateExcelStringLiteral(text), suffix)
---
> str1 = REGLINE % (text, suffix)
Addin/stub.Excel.regheader
12,14c12,14
< TempStrNoSize("\x0AGetAddress"),
< TempStrNoSize("\x03PR#"),
< TempStrNoSize("\x0AGetAddress"),
---
> TempStr(" GetAddress"),
> TempStr(" PR#"),
> TempStr(" GetAddress"),
Addins/Excel/xlutils.cpp
136c136
< if (xlretSuccess != Excel(xlUDF, &xStr, 2, TempStr(" GetAddress"),
&xCaller))
---
> if (xlretSuccess != Excel(xlUDF, &xStr, 2,
TempStrNoSize("\x0AGetAddress"), &xCaller))
Addins/Excel/framewrk.cpp
211a212,229
> LPXLOPER TempStrNoSize(LPSTR lpstr)
> {
> LPXLOPER lpx;
>
> lpx = (LPXLOPER) GetTempMemory(sizeof(XLOPER));
>
> if (!lpx)
> {
> return 0;
> }
>
> lpx->xltype = xltypeStr;
> // lpx->val.str = (PUCHAR) lpstr;
> lpx->val.str = lpstr;
>
> return lpx;
> }
Regards,
Plamen