Converting OCX, ActiveX and DLL calls to X#

This forum is meant for questions and discussions about the X# language and tools
Post Reply
User avatar
Kees Bouw
Posts: 97
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Converting OCX, ActiveX and DLL calls to X#

Post by Kees Bouw »

The project I am working on (a conversion from VO to X#) uses a lot of OLE stuff which I am trying to get working in X#. Specifically, there is a report generator called R&R ReportWorks that has an OCX and also a DLL. The OCX is of course used with OleControl, CreateEmbedding, InitAutoObject etc. Besides that it uses cOleMethod{} a lot, of which the VO Help says "This class is used for internal implementation only and is not intended to be used directly." An example of this is:

Code: Select all

METHOD AboutBox(		) CLASS RRSQLReport

	LOCAL oMethod  	AS cOleMethod
	LOCAL uRetValue	AS USUAL

	oMethod		      	:= cOleMethod{}
	oMethod:symName	  	:= String2Symbol("AboutBox")
	oMethod:iMemberid  	:= -552 
	oMethod:wInvokeKind	:= INVOKE_METHOD  

	uRetValue := SELF:oAuto:__Invoke(oMethod, DWORD(_BP+16),PCount())

	RETURN (uRetValue)
(Note: RRSQLReport inherits from OleControl, oAuto is an OleAutoObject)

The DLL is used with _DLL calls like this:

_DLL FUNCTION RRexecRuntime(HReport AS INT, bWait AS INT, FsCmdShow AS INT, eCode AS PTR, pPageCount AS PTR, EMsg AS PSZ, Emsgsize AS INT) AS BYTE PASCAL:RSRPT32.execRuntime

Not surprisingly, adding the OCX (rsw32.ocx) or the DLL (rsrpt32.dll) as a reference in X# results in an error (“Could not load file or assembly ‘rsrpt32.ddl’ or one of its dependencies. The module was expected to contain an assembly manifest.”)

I have several questions about this.

- I have seen "Example 5" in the X# documentation, but this is an entirely different OCX. Will the tricks used here work for any OCX or just for the one in the e-mail sample?
- What is the reason that these components are not supported in X#, is it the fact that they are 32-bit, or is the code unsafe, is it the missing assembly manifest? What would the requirements be for X# support? Would 64-bit ActiveX controls work?
- How can I get the cOleMethod{} code to work in X#, port the source code for this or is there a better way?
- I can't find anywhere what _BP exactly is. In VO it has the colour of "operators". It does not seem to exist in X#.

Many thanks to anyone who can shed some light on it!

Kees.
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Converting OCX, ActiveX and DLL calls to X#

Post by robert »

Kees,
Please read the X# documentation about how to convert code that uses an OCX. The topic about converting the Email example shows how to do that for the webbrowser OCX.
The short version of this is:
- create a windows form and put the OCX on that
- use that windows form if you can
- if you can't use the windows form, then apply the trick that is used in the example code.

Of course, you should also be able to call the functions exposed by the DLL if you have the right prototypes.
You would have to make _DLL FUNCTION declarations for these functions.

And finally, you can also contact the vendor and ask if they have a .Net implementation of their product.



Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Kees Bouw
Posts: 97
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Converting OCX, ActiveX and DLL calls to X#

Post by Kees Bouw »

Robert,

Thank you very much for your reply. I realise that you are very busy and do not have the time to elaborate. Nevertheless, I already mentioned that I had seen the OCX example in the X# documentation. Also, none of my questions were answered. The vendor does not have a .net implementation nor does he have any plans to create one. Maybe there is someone else in the forum who can tell me more?

Kees.
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Converting OCX, ActiveX and DLL calls to X#

Post by robert »

Kees,
- You cannot use the generated code from VO. This was designed for the VO OLE Runtime which is written in C/C++. We do not have that and do not want to recreate that because there is already excellend support for OCX controls in Windows.Forms. So there is NO need to migrate that code to X#. Simply throw that code way. Y
- _BP is a "pseudo variable" in VO. This represents the Base Pointer, which is used to address variables in assembly code on the stack. We do not have that in managed code.
- The tricks in the example should work for all OCXes. If you put the OCX on a form then 2 interop assemblies are created. One that describes the OCX itself (and contains the class that inherits from the Windows Forms Control class). The other contains the automation interface, which has methods like the AboutBox method that you showed in the generated VO code.
You may want to inherit from the code that was generated by VS and create a class with the same name that you were using in VO, to make the migration easier.
- How exactly this works with this particular OCX I do not know. I do not have the OCX.
- Most OCXes are either 32 bits or 64 bits. If the OCX worked with VO then it must be 32 bits, so you should also create a x86 assembly in X#.
- The _DLL FUNCTION calls should compile and work in X#. You do not have to add a reference to the RSRPT32 DLL but you have to make sure that the DLL can be found at runtime. The .Net framework will find the DLL, locate the function in the DLL (for example the execRuntime function), will convert the parameters etc. The function name is CASE SenSiTiVe. This is how we are calling functions in the Windows API to get the GUI Classes to run in .Net.

- If you want more help then you need to find someone that has done this, or you have to share the OCX and its documentation with Chris or me, preferably with an example file and the data files that it needs. Please do NOT send the whole app.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Kees Bouw
Posts: 97
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Converting OCX, ActiveX and DLL calls to X#

Post by Kees Bouw »

robert wrote: Tue Nov 28, 2023 4:00 pm - You cannot use the generated code from VO.
Robert,

Thank you very much for the answers, this is a big help. So all the code with cOleMethod{} is generated. I should have suspected that, because the module consists of a long list of accesses and assigns (the aboutbox being an exception) with similar code. One more question out of curiosity: what triggers this code to be generated in VO? It obviously is related to the OCX but how do you get from the OCX to this generated code?

Thanks again,

Kees.
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Converting OCX, ActiveX and DLL calls to X#

Post by robert »

Kees,

That code is generated from the Tools / Setup OLE Control menu option

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
ic2
Posts: 1798
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Re: Converting OCX, ActiveX and DLL calls to X#

Post by ic2 »

Hence general question to every reader:

Has anyone used R&R ReportWorks in VO and tried to get this working in X#?

Dick
Post Reply