Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB.NET pointer help

Status
Not open for further replies.

kevin97531

Programmer
May 1, 2005
1
US
I am trying to make a charting application in Visual Basic .NET 2003. I have software that allows me to make function calls to retrieve financial quotes. The problem is that I need to use pointers and I'm not sure how to do that in Visual Basic. The maker of the software provides structures to use for Delphi and C++ but not for Visual Basic. They also won't help unless I pay for tech support. Here is the description of the function that I need to use:


Delphi

function GetRealTimeData(Symbol: PChar; SymType: PChar; Expiry: PChar; Right: PChar; Strike: Double; Exchange: PChar; Currency: PChar; var RealTimeRec: PRealTimeRec): BOOL; stdcall external 'hocts.dll' name 'GETREALTIMEDATA';


C++

BOOL __stdcall GetRealTimeData(char* Symbol, char* SymType, char* Expiry, char* Right, double Strike, char* Exchange, char* Currency, LPREALTIMEREC* RealTimeRec);


Visual Basic

Public Declare Function GETREALTIMEDATA Lib "hocts.dll" (Symbol As String, SymType As String, Expiry As String, Right As String, ByVal Strike As Double, Exchange As String, ACurrency As String, RecArray As Long) As Boolean


Parameters
None

Return Values
If the function succeeds, the return value is nonzero.

RecArray
Pointer to array of the specified structures


Delphi Structure:
PRealTimeRec = ^TRealTimeRec;
TRealTimeRec = packed record
SymIdent: array[0..CSL_MAX_SYMBOL_LEN] of Char;
SymExchange: array[0..CSL_MAX_EXCHANGE_LEN] of Char;
SymSecType: array[0..CSL_MAX_SEC_TYPE_LEN] of Char;
SymExpiry: array[0..CSL_MAX_EXPIRY_LEN] of Char;
SymRight: array[0..CSL_MAX_RIGHT_LEN] of Char;
SymCurrency: array[0..CSL_MAX_CURRENCY_LEN] of Char;
Bid: Double;
Ask: Double;
Last: double;
DateTime: TSystemTime;
Volume: Double;
end;



C++ Structure:

typedef struct _REALTIMEREC {
char SymIdent[20];
char SymExchange[15];
char SymSecType[20];
char SymExpiry[30];
char SymRight[30];
char SymCurrency[20];
double Bid;
double Ask;
double Last;
SYSTEMTIME DateTime;
double Volume;
} REALTIMEREC, *LPREALTIMEREC;
;



I'm not sure how to make a pointer to a structure in Visual Basic. All I want to do is retrieve the Bid price. Does anyone know how I could go about doing this?


Thanks,
Kevin
 
Passing a variable ByRef passes a pointer to the address of the variable.

Create a local variable based on the structure and pass it ByRef. (For the strings in the structure use char arrays ie
SymIdent(19) as char. Arrays of char can be treated pretty much as strings, when the function returns.

Passing strike as ByVal is obviously correct for the double. The strings, however may be more difficult. PChars are pointers to ASCIIZ strings (ie varable length strings terminated with Chr(0)). If you know the maximum length of the strings, then you could probably get away with creating char arrays of the maximum size and pre-populating them with Chr(0)s and then passing them ByRef. Be careful however because if you select a size that is too small there would be problems when the dll trys to write to them. Otherwise you could try creating dynamic char arrays.

I'm not sure that using a string variable would work, but if you try it pass it as ByRef.

Parameters passed ByRef are simply pointers to variable in your program's address-space.

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top