[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1002
  • Last Modified:

VBScript code to call a sub in a DLL

I'm using FP2000, PWS w/W98.I want to call a sub (PROB3) in a DLL (MATH.DLL) using VBScript and put a variable generated by the sub (PROBLEM$) into a picturebox (Pbox) on an  ACTIVEX CONTROL (STU.OCX). Could I please see exact VBS Code using the references I put in parentheses. Are there any preliminaries I must do to ensure that the code works? Did I have to do something before I compiled the DLL or before I compiled the OCX re: add properties, methods, events or anything else?
Thanks !!!!
0
mathprof
Asked:
mathprof
  • 4
  • 4
  • 2
  • +1
1 Solution
 
ssiteCommented:
Unfortunately, VBScript can't call DLL's directly.

What you need to do is this:

In your OCX which you've probably created using VB, define a regular DECLARE statement for the DLL.

Use the DLL internally in the control. If you need to receive parameters from the VBS code, you should implement this as a method in side your OCX.

This way, VBS calls the VB OCX's method and it calls the DLL. You can return results and even set the OCX's properties without even it concerning VBS.
0
 
PBallCommented:
wrap them up :)

nice thing a wrapper is hehehe.

0
 
mathprofAuthor Commented:
You strategy almost works.
My DLL is math.dll my function is
function a101 (byval problem as string)
...
problem$="2+2="
end function
--------------------------

My OCX declare is
private declare function a101 Lib "math.dll" (byval problem as string)
error is: cant find entry point a101 ...
My revised Declare is:
Private declare function a101 Lib "math.dll" alias "#1" (byval problem as string)
no error
my ocx call is call a101
error is: argument not optional
my revised call is: call a101 (byval problem as string)
error is at word 'as': expected list separator or )
my revised call is: acll a101 (by val problem)
error is: runtime error 49 Bad DLL calling convention.
What now ?


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.

 
ssiteCommented:
I need the EXACT code of the DLL. The problem you have is that VB not only recognizes your function properly, it doesn't even recognize the DLL properly.
0
 
mathprofAuthor Commented:
How can I send you the code?

0
 
mathprofAuthor Commented:
I still am stuck at my call function. The Declare function is: Declare Function a101 Lib "math.dll" (byVal Problem as string) and is OK!!  I do not get an error. It DOES find the DLL. (I am not using alias).
When I run the OCX (design mode) and my call is
Call a101
I get an error at the Call :"Argument NOT optional)
When I start with (, VB suggests and I finish with byval problem as string). Yet when I run I get an error on the word AS "expected list separator or )".
When I Just use call a101 (problem) and run I get error 49 "BAD DLL calling convention."

0
 
ssiteCommented:
You can send me the code (DLL, APP) to ssite@netvision.net.il
0
 
yerffoegCommented:
I don't understand why ssite says that you can't call a DLL
function directly. Unless your DLL is not split into class
Modules (hence the Math.class where you don't mention the
class) This is what I do when calling ActiveX DLLs from VBScript.

<%
Dim Problem$

Set ReftoMathDLL = Server.CreateObject("Math.Class")
Problem$ = RefToMathDLL.Prob3("2+2")
%>
0
 
ssiteCommented:
Yes, yerrffoeg, but you are not calling a DLL. You are creating an instance of an ActiveX object which is stored in a DLL. What mathprof wants is to call a regular win32 DLL(which doesn't contain objects, but rather functions).

Oh yeah, can I get my points??
0
 
yerffoegCommented:
Oui, Je comprende.
0
 
mathprofAuthor Commented:
I'm giving ssite the points. However, I note that inasmuch as I did not receive his offer to look over my code because of a delay in receiving his e-mail, I got help from another source which incorporated his response to yerffoeg's comment.
My dll is:math911.dll
It has a class:questions which has a function: a101
My OCX (stuinput1.ocx) code follows:
'declaration
private objM as Math911.questions

sub geta101()
'create instance (when loading control)
Set onjM= New Math911.questions
'use the function
call onjM.a101(problem)
'the call returns variable:problem
end sub

My webpage code:   call stuinput1.geta101
0

Featured Post

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.

  • 4
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now