LPSTR &Value

35 views
Skip to first unread message

Roman Mishin

unread,
Jul 11, 2015, 12:31:16 AM7/11/15
to xbl...@googlegroups.com
Hi,

Could you please suggest a translation of the following C function:
extern "C" void __declspec(dllexport) __cdecl XLSGetCellValue(THandle AHandle, int SheetIndex, int Row, int Col, int MaxLen, LPSTR &Value);

In particular LPSTR &Value is of interest.

I have shallow understanding that this is a pointer to string passed by reference;
also I understand that XBLite's default data type is XLONG, so in .def file I did:

EXTERNAL CFUNCTION VOID XLSGetCellValue(AHandle,SheetIndex,Row,Col,MaxLen,@Value)

Here is how I call it:
...
XLSGetCellValue(hXlsFile,0,0,0,valLen,&cellVal)
PRINT
"cellVal ",CSTRING$(cellVal)
...
all passed values seem to be valid: SheetIndex,Row,Col,MaxLen.
hXlsFile is valid because I call other functions with this handle and they do work.

But execution does not proceed past XLSGetCellValue call. The compiled .exe silently
ignores all the code below, nothing is printed.

I also did:
XLSGetCellValue(hXlsFile,0,0,0,valLen,@cellVal)
or
XLSGetCellValue(hXlsFile,0,0,0,valLen,cellVal)
and
PRINT "cellVal ",cellVal ' to just see the address
but nothing is working.

Roman Mishin

unread,
Jul 12, 2015, 9:27:02 AM7/12/15
to xbl...@googlegroups.com
So, here is a working solution that I came up with:

Function declaration in .def file:


extern "C" void __declspec(dllexport) __cdecl XLSGetCellValue(THandle AHandle, int SheetIndex, int Row, int Col, int MaxLen, LPSTR &Value);

becomes

EXTERNAL CFUNCTION VOID XLSGetCellValue(AHandle,SheetIndex,Row,Col,MaxLen,Value)

Value or @Value makes no difference.

Here is the call in .x file:

cellVal$=" " ' should have some (any) initial value, otherwise won't work
XLSGetCellValue(hXlsFile,0,3,6,valLen,&&cellVal$) ' pass handle address
PRINT "cellVal$ ",CSTRING$(&cellVal$) '
dereference data address

Cheers..

Guy Lonne

unread,
Jul 12, 2015, 7:34:35 PM7/12/15
to xbl...@googlegroups.com
Hi Roman,

I'd rather translate:
extern "C" void __declspec(dllexport) __cdecl XLSGetCellValue(THandle
AHandle, int SheetIndex, int Row, int Col, int MaxLen, LPSTR &Value);

as XBLite:
EXTERNAL CFUNCTION VOID XLSGetCellValue (XLONG AHandle, SSHORT
SheetIndex, SSHORT Row, SSHORT Col, SSHORT MaxLen, XLONG ptrValue)

Why?
THandle -> XLONG
int -> SSHORT
LPSTR &-> XLONG

Hope this helps!

Bye! Guy

Roman Mishin

unread,
Jul 13, 2015, 1:38:14 PM7/13/15
to xbl...@googlegroups.com
Hi Guy,
 
int -> SSHORT

Good tip. Thanks!

David Szafranski

unread,
Jul 13, 2015, 5:43:59 PM7/13/15
to xbl...@googlegroups.com
As Guy suggested, using SSHORT or USHORT type variable should make a difference. In general, you should be able to pass C string values by address.

EXTERNAL CFUNCTION VOID XLSGetCellValue(XLONG AHandle, SSHORT SheetIndex, SSHORT Row, SSHORT Col, SSHORT MaxLen, XLONG lpstrValue)


cellVal$ = NULL$(256)                                  ' reserve space for string
XLSGetCellValue (hXlsFile, 0, 3, 6, SIZE(celVal$), &cellVal$) ' pass string length and address
PRINT "cellVal$ ", CSTRING$(&cellVal$)


--
You received this message because you are subscribed to the Google Groups "xblite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xblite+un...@googlegroups.com.
To post to this group, send email to xbl...@googlegroups.com.
Visit this group at http://groups.google.com/group/xblite.
For more options, visit https://groups.google.com/d/optout.

Roman Mishin

unread,
Jul 13, 2015, 9:08:29 PM7/13/15
to xbl...@googlegroups.com
cellVal$ = NULL$(256)
...,SIZE(celVal$),...

That makes the subject clearer to me. Thank you.

There is a special function in the library to get the length of cell value.
That way, the final code is this:

valLen%%=XLSGetCellValueLength(hXlsFile,0,3,6)
cellVal$
=NULL$(valLen%%)
XLSGetCellValue(hXlsFile,0,3,6,valLen%%,&&cellVal$)
PRINT
"cellVal$ ",CSTRING$(&cellVal$)

P.S. This call does not work:
XLSGetCellValue(hXlsFile,0,3,6,valLen%%,&cellVal$)

Reply all
Reply to author
Forward
0 new messages