Solved

How to resolve PSafeArray from dll

Posted on 2006-11-17
5
368 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 500 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

821 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