?
Solved

We are testing with a third party dll within the Powerbuilder development environment

Posted on 2008-02-03
14
Medium Priority
?
432 Views
Last Modified: 2013-12-26
passing variables to the dll functions and receiving variable values back.  Everything works fine except for the return of string variable values which are mostly non letter characters.  
Function declaration with the problem:
int tixGetRecordA(TCursorHandle Cursor, const char **RecordID, const char **RecordData, const char **FoundTerms, int *Precision, int *Score, WORD CodePage); 
 
Powerbuilder external function declarations for the variables in order are set as follows uLong Cursor, Ref String RecordID, Ref String RecordData, Ref String FoundTerms, Ref Integer Precision, Ref Integer Score, uInt codePage.
 
Proper values are being returned except for the String variables?  Wondering what could be causing the issue?

Open in new window

0
Comment
Question by:peachkj
13 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 20809322
And what is the code of the function in question?
0
 
LVL 1

Author Comment

by:peachkj
ID: 20810469
The third party dll is for full text indexing of a database column.  Documentation is in the attached MSWord function where the string values are not returning correctly is tixGetRecordA in the tixProcessQuery section at the end of the document.
AlphaTIX.doc
0
 
LVL 1

Author Comment

by:peachkj
ID: 20810671
Specification for third party function tixGetRecordA where we are not succeeding in having proper strings returned.
Function-tixGetRecordA.doc
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 14

Expert Comment

by:sandeep_patel
ID: 20811356
As you are passing string arguments by reference to external functions (any dlls or database stored procedures) you may need to allocate memory to those variables before calling function. FYI...Memory allocation is not required for other datatypes when you pass by reference.

See example in code snippet. Hope this will work for you...

Regards,
Sandeep
Function declaration
int tixGetRecordA(uLong Cursor, Ref String RecordID, Ref String RecordData, Ref String FoundTerms, Ref Integer Precision, Ref Integer Score, uInt codePage); 
 
Clicked Event of button
 
string ls_recordid,ls_recorddata,ls_foundterms
integer li_return
//suppose max return length of ls_recordid,ls_recorddata,ls_foundterms are 10,1000& 100 respectively. Then assign memory as below
ls_recordid = space(10)
ls_recorddata = space(1000)
ls_foundterms = space(100)
//now call function
li_return = tixGetRecordA(.....all arguments......)

Open in new window

0
 
LVL 1

Author Comment

by:peachkj
ID: 20811387
I have done the memory allocation as you've indicated, however this has not worked.  In the function declaration (int tixGetRecordA(TCursorHandle Cursor, const char **RecordID, const char **RecordData, const char **FoundTerms, int *Precision, int *Score, WORD CodePage) there are double asterisks ** on the Char variables (RecordID, RecordData, and FoundTerms) that are providing the problem.  Checking some C++ documentation these double ** inidicate a pointer to a pointer pointing to a variable location.  So the question now becomes how does Powerbuilder handle this? if in fact this is the issue?
0
 
LVL 14

Expert Comment

by:sandeep_patel
ID: 20811867
according to me it should be handled with by reference only. Make sure that you have assigned the same memory that function is supposed to return. Or if you can know how to call this function from VB it may help.
0
 
LVL 14

Expert Comment

by:sandeep_patel
ID: 20811927
one more thing...in PB 10 and later versions you have to put keyword ';ansi' with external function declaration if you have any string variable as reference argument.

{ access } FUNCTION returndatatype name ( { { REF } datatype1 arg1,
    ..., { REF } datatypen argn } ) LIBRARY "libname"
    ALIAS FOR "extname{;ansi}"

Don't remember whether it was there in pb6.5 or not?
0
 
LVL 1

Author Comment

by:peachkj
ID: 20818447
I've checked PB6.5 documentation and the "ansi" ALIAS option is not documented.  Changed code and when the program was run received an error message concerning the "ansi" option.  So this is not an option for this version.   So we're still looking.

No sure of what you mean by your comment: "Make sure that you have assigned the same memory that function is supposed to return. "

 Considering upgrading PB.
0
 
LVL 14

Expert Comment

by:sandeep_patel
ID: 20818478
"Make sure that you have assigned the same memory that function is supposed to return. " - it means if function tixGetRecordA returns/assigns 1250 characters to reference variable then before passing that variable you have to assign that much memory.

e.g.
ls_recorddata = space(1250)

In my previous post space(1000) was just for example you have to put the exact or more memory that i believe.
0
 
LVL 2

Expert Comment

by:mj_norwich
ID: 20825448
In 32-bit world PowerBuilder can only call external functions that have used the standard calling sequence (pascal calling sequence for 16-bit) - check the third party DLL

0
 
LVL 1

Author Comment

by:peachkj
ID: 20836811
We've significantly increased the amount of each ** variable but this does not resolve the issue.  As well, have tested it under PB 10.5 at an associated company with the  "ALIAS FOR "extname{;ansi}"
included in the declaration of the of the PB external function, again with no success.  Because all other variables are being returned successfully, we believe that it is an issue with how PB deals with the double ** pointer pointing to another pointer pointing to the stored value.   Is there a PB function to use with the pointer memory value to reference the stored values?  Hope that makes sense.
0
 
LVL 1

Accepted Solution

by:
peachkj earned 2000 total points
ID: 20863827
Solution determined:

Local function declaration:
Function Integer tixGetRecordA(Long l_Cursor, Ref Long l_RecID, Ref Long l_RecData, Ref Long l_Found, Ref Integer i_Precision, Ref Integer i_Score, Int i_CdPg) LIBRARY "tix.dll"

Code in script:
li_Result = tixGetRecordA(ll_Cursor, ll_RecordID, ll_RecordData, ll_FoundTerms, li_Precision, li_Score, li_CodePage)
Use the PB String with the keyword "ADDRESS"  and a local variable as follows
            ls_RecordIDPt = String(ll_RecordID, "ADDRESS")            
            ls_RecordID = ls_RecordIDPt

ls_RecordID provides the desired information.
0
 
LVL 1

Expert Comment

by:Vee_Mod
ID: 20966778
Force accepted.
Vee_Mod
Community Support Moderator
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

593 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question