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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Parameter Problem

Status
Not open for further replies.

hkung

Programmer
Jan 9, 2001
19
0
0
MY
Hi all,

I have an VB Active X dll, namely VBDLL.dll, with the following function declaration :

/////////////////////////////////////
Private Declare Function EncryptOnly Lib "CDLL.dll" _
Alias "_EncryptOnly@28" (ByVal CSN As String, _
ByVal CSNLen As Long, ByVal PlainTxt As String, _
ByVal PlainLen As Long, ByVal IV As String, _
ByVal CipherTxt As String, ByRef CipherLen As Long) As Long
/////////////////////////////////////

All the parameters are input parameters except the last two, which are CipherTxt and CipherLen that are output parameters.

(Notes : CDLL.dll is a C Win32 dll.)

The following function is in the Active X dll :

///////////////////////////////////////////////
Public Function Encrypt(ByVal CSN As String, _
ByVal CSNLen As Long, ByVal PlainTxt As String, _
ByVal PlainLen As Long, ByVal IV As String, _
CipherTxt As String, CipherLen As Long)

Dim CipherTxt1 As String
Dim CipherLen1 As Long

CipherTxt1 = String(2000, vbNullChar)
CipherLen1 = 2000

ReturnValue = EncryptOnly(CSN, CSNLen, PlainTxt, PlainLen, IV, CipherTxt1, CipherLen1)

CipherTxt = CipherTxt1
CipherLen = CipherLen1
End Function
/////////////////////////////////////////////////


When ASP page calls the Encrypt function in the Active X dll, it can successfully pass in the input parameter.

The ASP codes snippet is as follows :
///////////////////////////////////////////////
Set g_oEracom = Server.CreateObject("VBDLL.CVBDLL")

g_oEracom.Encrypt CStr(g_sCSN), CLng(g_lngCSNLen), CStr(g_sPlainTxt), CLng(g_lngPlainLen),CStr(g_sIV),CStr(g_sCipherTxt), CLng(g_lngCipherLen)

If Err.number <> 0 Then
Response.Write &quot;Encrypt function failed!<br>&quot;
Response.Write &quot;Reason: &quot; &amp; Err.description &amp; &quot;<br>&quot;
Set g_oEracom = Nothing
Response.End
Else
Response.Write &quot;Here are the results for Encrypt function:<br>&quot;
Response.Write &quot;CipherTxt = &quot; &amp; g_sCipherTxt &amp; &quot;<br>&quot;
Response.Write &quot;CipherLen = &quot; &amp; g_lngCipherLen &amp; &quot;<br>&quot;
End If
////////////////////////////////////////////

However, the output parameters cannot be passed out successfully. It seems that the ByRef keyword is the one that's causing the problem. I tried not to explicitly cast the data type in the function calling in ASP page, but it gives Type Mismatch error.

Is it anything that we have to do in order to pass the parameter out from the function by reference?

Rgds,
hkung

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top