Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to resolve PSafeArray from dll

Posted on 2006-11-17
5
Medium Priority
?
386 Views
Last Modified: 2010-04-04
I have a dll wrapping a webservice call (C#.net).  
When I import the library to Delphi, the return type changes to PSafeArray.

Here's the signature from the TLB:
    procedure GetNumberRange(const connString: WideString; const nameCaller: WideString;
                             identCaller: Integer; const orderRef: WideString; countryCode: Word;
                             quantity: LongWord; oneRange: WordBool; numbers: PSafeArray); safecall;
Here's my call from Delphi (Same as an exmple I got here):
  a:  Variant;
begin
  bnds[0].LowBound := 0;
  bnds[0].ElementCount := 0;
  ws := CoResETag.Create();
  psa := SafeArrayCreate(varOLEStr,1,bnds);
 try
    ws.GetNumberRange(tbConnString.Text,tbNameCaller.Text,StrToInt(tbIdentCaller.Text),tbOrderRef.Text,     StrToInt(tbCountryCode.Text), StrToInt(tbQuantity.Text), true, psa);
/****/
I get:  Specified array was not of the expecting type  when executing this.
Help please
0
Comment
Question by:jlaurin
  • 2
5 Comments
 
LVL 21

Expert Comment

by:ziolko
ID: 17978325
try this

var bound: TSafeArrayBound;
    sa: PSafeArray;

bound.lLbound := 0;
bound.cElements := 5;
sa := SafeArrayCreate(varVariant, 1, bound);

ziolko.
0
 

Author Comment

by:jlaurin
ID: 17979192
Nope.  Still getting the same error.
0
 
LVL 21

Accepted Solution

by:
ziolko earned 2000 total points
ID: 17979870
var var_array: Variant;

var_array := VarArrayCreate([0,0], varVariant);
and then use var_array instead of psa
-or-
var var_array: Variant;
     lck: Pointer;

var_array := VarArrayCreate([0,0], varVariant);
lck := VarArrayLock(var_array);
and use: lck (dont forget to call VarArrayUnlock)

ziolko.
0
 
LVL 1

Expert Comment

by:Computer101
ID: 21133158
Forced accept.

Computer101
EE Admin
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

885 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