Callling DLL Functions from BASIC+ (OpenInsight 32-Bit)
At 20 JUN 2009 04:26:47AM Chee Onn Wu wrote:
I try to create my own DDL and call it within Visual studio. Its work fine.
Then I try to call the DLL in OpenInsight but I failed with the Runtime Error
"ENG0805: TEST,line 6. Function MYCALC_ADD" does not exist in dynamic link library MYCALC."
1) This is my DLL I created in Visual Studio and name it MYCALC.dll
==============================
MYCALC.dll
==============================
Public Class Class1
Public Function MYCALC_ADD(ByVal first As Integer, ByVal sec As Integer)Dim ans As Integerans=first + secReturn ansEnd FunctionPublic Function MYCALC_SUB(ByVal first As Integer, ByVal sec As Integer)Dim ans As Integerans=first - secReturn ansEnd FunctionPublic Function MYCALC_MUP(ByVal first As Integer, ByVal sec As Integer)Dim ans As Integerans=first * secReturn ansEnd FunctionPublic Function MYCALC_DIV(ByVal first As Integer, ByVal sec As Integer)Dim ans As Integerans=0Return first / secEnd FunctionEnd Class
==============================
2) Then I copy MYCALC.dll under the root folder "OpenInsight721"
3) Register to SYSPROCS by name it as "DLL_MYCALC"
==============================
SYSPROCS -] DLL_MYCALC
==============================
MYCALC.dll
INT STDCALL MYCALC_ADD(INT, INT)
INT STDCALL MYCALC_SUB(INT, INT)
INT STDCALL MYCALC_MUP(INT, INT)
INT STDCALL MYCALC_DIV(INT, INT)
==============================
4) Run System Monitor and Execute "Run Declare_FCNS "DLL_MYCALC"
Then it was create in SYSOBJ table5) Test with my Program
==============================
SUBROUTINE TEST(ARG)
DECLARE FUNCTION MYCALC_ADD
ANS=MYCALC_ADD(1,2)
CALL MSG(@WINDOW,ANS)
RETURN
==============================
Runtime error when execute
"ENG0805: TEST,line 6. Function MYCALC_ADD" does not exist in dynamic link library MYCALC."
Do I miss out anything? Help much appreciated. Thanks first!
At 20 JUN 2009 08:23AM Bob Carten wrote:
Chee,
The Declare Fcns succeeds with DLLs written in C or C++.
It looks like you are creating your code in VB.Net ( Visual Studio 2003 or above), so you are creating a .Net dll. OI can use your dll as an OLE object if you compile it with the COM Interop interfaces.
You can find help on Google, for instance
see http://social.msdn.microsoft.com/Forums/en-US/vside2008/thread/9f84bdf7-aace-4a57-a3e4-3863a0efb647
When have you dll, you can use it in OI using syntax like
obj=PleCreateInstaince("MYDLL.CLASS1")
result=OetCallMethod(obj, 'MYMETHOD', myparam)
Note,
In OI 9.1 I believe you can use your dll without adding the COM interface using the new .Net capabilities.
- Bob
At 20 JUN 2009 09:27AM Chee Onn Wu wrote:
Bob Carten,
Thanks a lot of your quick response.
By registering the dll as COM object mean I have to do it at the Developer PC and also the End User PC?
How if I use Visual Studio and create the dll using C++?
Thanks first
At 22 JUN 2009 01:03PM Bob Carten wrote:
If you use .net to create com Object you will need to create an installer too, to accomplish the .Net and the COM registrations.
You can make the installer from Visual Studio by adding a deployment project to your regular project. I don't know enought about C++ dlls to give good advice.
- Bob
At 23 JUN 2009 02:33AM Aaron Thorp wrote:
Well i was just testing out this feature with Visual Studio 2008, and i have managed to get it to work perfectly inside OI…
I created a new class project, then add a "COM Class", this will setup the class and it will be expsoed to the COM, giving it a GUID and everything necessary, add all your functions and properties that you want exposed in there then add an installer prject, add the Project Output to the Application folder and to the Global Assembly Cache Folder, build the installer, install it and then it will work (if you do an update to the dll, you need to restart OI for it to recognise it)
At 24 JUN 2009 12:30PM Bob Carten wrote:
Nice.
Can be a great way to take .NEt examples from places like codeproject.com and use them in OI.
Also, with OI 9.1, you can use .Net dlls directly without any need to compile a wrapper.
At 30 JUN 2009 10:56AM Chris Stark wrote:
I have been attempting to develop a C# dll using Visual Studio 2008 for use with our OI developed product, and I'm unable to determine what I'm doing wrong. I'm using OI 8.0.7.
This is what I have so far:
A Class Library Project has been defined (dll)
A Class in the project with a public constructor
A single public method with 3 int parameters has been defined with a return parameter of an int.
The project properties have been configured so that ComVisible is checked, and Register for ComInterop is checked as well.
The AssemblyInfo.cs has been generated with a GUID entry, and ComVisible set to true.
Regarding the previous post (Aaron Thorp 6/23/09):
What is the COM Class that is referred to?
Why is the installer needed? If its just needed to copy the file to the target system, let's assume for simplicity sake that I will be copying the file manually.
What does the following statement mean: "add all your functions and properties that you want exposed in there" Are there additional properties that need to be set in the Assembly file, or the Class definition in order for the method to be seen by OI?When I copy the file to the OI directory and attempt to run a test with the following code:
obj=OLECreateInstance("Testdll.ClassA")
status=OLEStatus()
The obj is blank:
The status is: -2147221005 result=OleCallMethod(obj, 'MethodA', 1, 2, 3) status=OLEStatus() The result is blank:
The status is -2147418113Any help here would be greatly appreciated. I've been struggling with this for several days now. There must be some key piece of the puzzle I am missing.
Thanks in advance.
At 30 JUN 2009 01:58PM Bob Carten wrote:
Hi Chris
I did a Vs2008 project using the .Net ecncryption classes.
I am no expert, but here is what I know:
You must add a progid to the class definition:
public class RijndaelSimple ProgId("rtiCrypt.Crypto") public sealed class Crypto { …. You must Set Make COM visble=true in the project compiler options You must Make an installer. Without the installer the dll will only work on the VS2008 machine which compiled the project. I believe the installer adds the entries to the GAC, which is .Net version of registry, as well as adding the progid to the registry. Copying without installer will not create the GAC entries. If and only if you follow these steps you should be able reference the object in OI with standard OLE syntax. crypto=OleCreateInstance("rtiCrypt.Crypto") - Bob </QUOTE> —- === At 06 JUL 2009 12:49AM Chee Onn Wu wrote: === <QUOTE>Thank you for all your replies. Although I still did not manage to get it to work, I really appreciate the responses. I have tried to follow the steps as much as posible, here is what I did. 1. Added a new project in Visual Studio 2008 Pro Visual Basic ] Class Library Named as MyDLL 2. Added a Com Class inside the Project, typed in the function. Inside the com class looks like this _ Public Class ComClass1 Public Const ClassId As String=c4d99ab4-b058-41f8-af2c-fb550c7e30a0" Public Const InterfaceId As String=be969fe8-67f2-454d-ba64-7bb38a50e36c" Public Const EventsId As String=84f1b1cd-bf7f-417b-8c31-b092d03901a5" Public Sub New() MyBase.New() End Sub Public Function MyFunction() As String Return "The function is successfully called." End Function End Class 3. Checked the Register Com Interop inside the project Properties 4. Then I moved on to creating a setup file. By Adding a Setup Project under Other Project Types ] Setup and Deployment 5. Then Add in these things into the Setup - Primary Output - Localized Resources - Content Files - Debug Symbols - XML Serialization Assemblies 6. The Setup is built and installed into my OI Developer Folder. 7. I then created a testing subroutine to see if I got it right SUBROUTINE TEST(ARG) DECLARE FUNCTION OLECREATEINSTANCE, OLECALLMETHOD OBJ=OLECREATEINSTANCE("MYDLL.ComClass1") A=OLESTATUS() CALL MSG(A) RESULT=OLECALLMETHOD(OBJ,'functionone', '') B=OLESTATUS() CALL MSG(B) CALL MSG(RESULT) RETURN The results were A=-214221005 B=-2147418113 RESULT=NULL I am not sure which part I have did any errors. Please help. Many thanks in advanced. </QUOTE> View this thread on the Works forum...