.NET made OCX vs Progress events

Cougar

New Member
Hi, I was wondering if anyone ever used an OCX made in .NET in conjunction with Progress 9. I managed to make a simple OCX in C#. Method calls work ok, but I don't seem to be able to implement a COM event sink properly. The events are just ignored by Progress, even though the OCX appears to be valid and Progress COM Object Viewer displays a correct syntax for my event handler. Any ideas/pointers would be greatly appreciated. Thanks.

The sources - Progress side:
Code:
DO:
DEF VAR i-test AS INT NO-UNDO.
DEF VAR ch-test AS COM-HANDLE NO-UNDO.
 
CREATE "ComTest.TestClass" ch-test.
IF VALID-HANDLE(ch-test) THEN DO:
	ch-test:ENABLE-EVENTS("TestClass").
	/* the TestMethod is called OK, but it should raise an event */
	/* well, it doesn't */
	i-test = ch-test:TestMethod("blah blah").
	MESSAGE i-test.
END.
END.
 
 
PROCEDURE TestClass.TestEvent:
MESSAGE "TestEvent".
END PROCEDURE.



The sources - .NET side (C#):

Code:
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
 
 
namespace ComTest
{
[ComVisible(false)]
public delegate void TestDelegate();
 
 
[GuidAttribute("31593BBD-B67E-4fd5-AE26-F0CA73A81B80")]
[ProgId("ComTest.TestClass")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComSourceInterfaces("ComTest.TestClassEvents")]
public class TestClass
{
public TestClass()
{
}
 
public int TestMethod(string Param)
{
if(DialogResult.Yes==MessageBox.Show(Param, "", MessageBoxButtons.YesNo))
{
	 // this should raise the event
	// but TestEvent is always null
	if(TestEvent!=null) TestEvent();
}
return 1234;
}
 
public event TestDelegate TestEvent;
}
 
 
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface TestClassEvents
{
void TestEvent();
}
}
 

Luke Gardiner

New Member
I'm thinking it must be somewhere on the 4GL side since the object viewer displays the correct syntax. I've made an OCX in Delphi7 that intercepts windows messages and works in Progress 9.1D. However to use it i've been using code that looks similar to the following:

To Create:

DEFINE VARIABLE OCXFile AS CHARACTER.
DEFINE VARIABLE chCtrlFrame AS COM-HANDLE.
DEFINE VARIABLE CtrlFrame AS WIDGET-HANDLE.
DEFINE VARIABLE aOCX AS COM-HANDLE.

CREATE CONTROL-FRAME CtrlFrame ASSIGN
FRAME = FrameHand.
CtrlFrame:NAME = "CtrlFrame":U.
OCXFile = SEARCH ( "ToolBarForm.wrx":U ).
chCtrlFrame = CtrlFrame:COM-HANDLE.
chCtrlFrame:LoadControls( OCXFile, "CtrlFrame":U ).
aOCX = chCtrlFrame:AppBlastX.

To Use:

PROCEDURE CtrlFrame.AppBlastX.MouseMessage:
DEFINE INPUT PARAMETER MsgVal AS INTEGER NO-UNDO.
DEFINE INPUT PARAMETER wParam AS INTEGER NO-UNDO.
DEFINE INPUT PARAMETER lParam AS INTEGER NO-UNDO.
DEFINE INPUT PARAMETER Result AS INTEGER NO-UNDO.

MESSAGE "Mouse Event Intercepted:" MsgVal VIEW-AS ALERT-BOX
END.

However this first requires me to create a form using the AppBuilder and to then place my OCX on it. The AppBuilder then spits out the "ToolBarForm.wrx" file. The problem with this is, I haven't figured out a way to create multiple objects from the one OCX. If I need 4 scroll bars for instance, I have to put 4 scrollbars on the form.
Your code is interesting however because you dont appear to use an .wrx file. I was wondering if the OCX actually appears in the progress window and have you managed to get the events to fire, since we wish to use our OCX's, in a fashion similar to the way you attempted.
 

Cougar

New Member
Well, my goal was not an interactive ActiveX control which can be placed on a progress frame, just a generic worker COM object, so unfortunately I can't help you there, I'm sorry.
As for the events, I came to a conclusion it's not possible for Progress to catch events from a .NET generated COM object. There is a knowledge base article on this (solution ID P56004), unfortunately the solution presented is not applicable to .NET (as far as I know). So I'm using the message blaster control instead, similarly as you do in the above example.
 

sedge

New Member
Did you get anywhere with this? We would like to be able to generate Events that Progress (V9) can trap in .NET DLLs, preferably VB.NET but any .NET language will do.
It looks like we got to a similar place to you, this article
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconRaisingEventsHandledByCOMSink.asp
It appears that we are close because we can get the events to trigger in VB6, but not in Progress. I'm happy to share what we've done if you are still working on it.
Steve
 

Luke Gardiner

New Member
I'm not 100% certain but I'm pretty sure I read somewhere that it is not possible to have Progress respond to events from DLL's, only OCX's - I think it might of been in the Progress External Program Interface pdf but I can't find the statement at the moment

I've only been using OCX's created in Delphi7 but I'm positive there should be no difference in their use in Progress than from one's created in any other programming language, whether its C++, VB or .NET. It should be fairly easy to change your DLL into an OCX, typically what I did for my OCX's, is just extend an Image or Button object and added the extra stuff I needed. The button is then hidden but can still generate events.
 

sedge

New Member
We have a working example of Progress accepting events (mail arriving) from the Microsoft Outlook DLL. You just use the <com-handle>:ENABLE-EVENTS like in your example. I also found another article that suggests that Progress can't do events from VB. That may be a bit of a red herring because VB doesn't implement IDispatch by default, but it can be done.
My main problem with OCX is that most of my knowledge is with VB.NET, which doesn't create OCX. We had someone develop an OCX in VB6 but the events didn't work in Progress. It will be fairly easy for me to extend to C#.NET or J#.NET but more difficult to extend backwards to C++ or Visual Studio 6 (even if we could get a copy).
 

Cougar

New Member
Did you get anywhere with this?
Unfortunately not. I thought I'd use the Message Blaster OCX with combination of SendMessage API calls from the .NET object to trigger events in Progress. It works for simple things, but the Progress event handler cannot execute any "blocking command", such as WAIT-FOR or PROCESS EVENTS, and that's kinda...useless for me because I need to display a Progress window as a reaction to the .NET generated event but I can't because the window uses WAIT-FOR. So, I'm hopeless at the moment :(
 
Top