473,386 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problem getting events from C# to VJ++

We've been unable to get events working going from C# to VJ++. We
think that the C# component is being exposed properly as a
ConnectionPoint, and the Advise() from the VJ++ side seems to be
working, because the delegate on the C# side has 1 item in its
invocation list after the Advise(). However when we try to make the
callback, we get:

System.NullReferenceException: Object reference not set to an instance
of an object
at System.RuntimeType.InvokeDispMethod(String name, BindingFlags
invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers,
Int32 culture, String[] namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags
invokeAttr, Binder binder, Object target, Object[] args,
ParameterModifier[] modifiers, CultureInfo culture, String[]
namedParameters)
at System.RuntimeType.ForwardCallToInvokeMember(Strin g memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)
at IWeatherEvents.OnWeatherChanged(Int32 nTemperature)
at TemperatureComponent.StateChange(Object sender, EventArgs args)
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.DebuggableCallback(IntP tr hWnd, Int32
msg, IntPtr idEvent, IntPtr dwTime)

We'd appreciate help. We have a significant code base of VJ++ and
we've determined that the JCLA has too many issues, so we're going to
have to be hybrid for a little while. I think this is supposed to
work.

ITemp.idl
---------
/////
import "oaidl.idl";

interface ITemp; // defined below
interface IWeatherEvents; // defined below

[
uuid(ABA21482-DDE2-4cf8-9BF9-D95464AC77C2),
helpstring("ITemp type library"),
version(1.0)
]
library LTempLib
{
importlib ("stdole2.tlb");

// out going interface ///////////////////////
[
object,
uuid(36EAE5EA-633E-474f-B6F1-5CDE5552487E),
helpstring("IWeatherEvents"),
oleautomation
]
interface IWeatherEvents : IUnknown
{
[helpstring("IWeatherEvents callback")]
HRESULT OnWeatherChanged( [in] long nTemperature );
}

[
object,
uuid(9F0C939C-99E2-4a07-94AC-9D84E25AF8EF),
helpstring("ITemp"),
oleautomation,
pointer_default(unique)
]
interface ITemp : IUnknown
{
[propput,helpstring("Set the temp")]
HRESULT Temperature([in] float t);
[propget,helpstring("Get the temp")]
HRESULT Temperature([out,retval] float *t);
[helpstring("Display temp")]
HRESULT DisplayCurrentTemperature();
};

//////////////////////////////////////////////
interface ITemp;
[
uuid(33FE55E3-C85B-4475-B7B4-0B5196FAB0E7)
]
coclass InsideCOM
{
interface ITemp;
[source] interface IWeatherEvents;
}
}
Class1.cs
---------
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
// Outgoing interface which the sink implements
[InterfaceType(ComInterfaceType.InterfaceIsIDispatc h)]
[GuidAttribute("36EAE5EA-633E-474f-B6F1-5CDE5552487E")]
public interface IWeatherEvents
{
void OnWeatherChanged( int nTemperature );
}

// delegate representing the OnWeatherChanged method
// of the outgoing exposed to COM aware clients.
public delegate void WeatherChangedDelegate( int nTemperature );

// [InterfaceType(ComInterfaceType.InterfaceIsDual)]
//public interface ITemperature
//{
// float Temperature { get; set; }
// void DisplayCurrentTemperature();
//
//}

// this is required to tell typelibrary generation tool REGASM.EXE
// to export the public members of TemperatureComponent into a default
// Class Interface in the generated typelibrary
[
//ComSourceInterfacesAttribute(typeof(IWeatherEvents )),
ComSourceInterfaces("IWeatherEvents"),
GuidAttribute("33FE55E3-C85B-4475-B7B4-0B5196FAB0E7"),
ProgId("TemperatureComponent.TemperatureComponentI nterface")
]

// this tells the type lib generation tools to add this class
// along with all of its methods and properties to the typelib file.
//[ClassInterface(ClassInterfaceType.AutoDual)]
public class TemperatureComponent : LTempLib.ITemp
{
private float m_fTemperature = 0;
private Timer _t;

// define an event associated with the WeatherChangedDelegate
private event WeatherChangedDelegate OnWeatherChanged;

// Public Constructor
public TemperatureComponent()
{
m_fTemperature = 30.0f;
_t = new Timer();
_t.Interval = 1000; // 1 seconds
_t.Tick += new EventHandler(StateChange);
_t.Enabled = true;
}

private void StateChange(object sender, EventArgs args)
{
m_fTemperature++;
if( null != OnWeatherChanged )
{
System.Delegate[] foo = OnWeatherChanged.GetInvocationList(); //
just used to check in debugger that there is one thing to invoke
Object bar = OnWeatherChanged.Target; // didn't tell me anything
helpful just _ComObject
OnWeatherChanged( (int)m_fTemperature ); // This call causes the
exception
}
}

//WeatherIndications GetWeatherIndications();

//Public Property Accessors (Defines get/set methods)
public float Temperature
{
get { return m_fTemperature; }
set { m_fTemperature = value;}
}/* end Temperature get/set property */

// Public Method that displays the Current Temperature
public void DisplayCurrentTemperature()
{
String strTemp = String.Format("The current temperature at
Marlinspike is : " +
"{0:####} degrees fahrenheit", m_fTemperature);
MessageBox.Show(strTemp,"Today's Temperature");
}/* end DisplayCurrentTemperature */

// Another public method that returns an enumerated type
//public WeatherIndications GetWeatherIndications()
//{
// if(m_fTemperature > 70)
// {
// return WeatherIndications.Sunny;
// }
// else
// {
// // Let's keep this simple and just return Cloudy
// return WeatherIndications.Cloudy;
// }
//}/* end GetWeatherIndications */

}/* end class Temperature */
Form1.java (VJ++)
----------
import com.ms.wfc.app.*;
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;
import com.ms.wfc.html.*;
import com.ms.com.*;

import itemp.ITemp;
import itemp.IWeatherEvents;
import itemp.InsideCOM;
/**
* This class can take a variable number of parameters on the command
* line. Program execution begins with the main() method. The class
* constructor is not invoked unless an object of type 'Form1' is
* created in the main() method.
*/
public class Form1 extends Form implements itemp.IWeatherEvents
{
Object o;
ITemp it;
private int cookie = -1;

private IWeatherEvents m_iEventListener = null;

public Form1()
{
System.setOut( com.ms.debug.Debugger.out );
System.setErr( com.ms.debug.Debugger.out );
// Required for Visual J++ Form Designer support
initForm();
try
{
//TemperatureComponent t = new TemperatureComponent();
com.ms.com._Guid g = new com.ms.com._Guid(
"{33FE55E3-C85B-4475-B7B4-0B5196FAB0E7}" );
o = com.ms.win32.Ole32.CoCreateInstance(
g,
null,
com.ms.win32.win.CLSCTX_INPROC_SERVER,
InsideCOM.iid );
it = (ITemp)o;

IConnectionPoint cp = null;

IConnectionPointContainer container = (IConnectionPointContainer)o;
cp = container.FindConnectionPoint( IWeatherEvents.iid );
//cookie = cp.Advise( (IUnknown)
com.ms.com.ComLib.makeProxyRef(this) );
cookie = cp.Advise( this ); // didn't seem to matter whether
proxyref or not

} catch( Exception e )
{
e.printStackTrace();
String s = e.getMessage();
com.ms.wfc.util.Debug.println( s );
}

// TODO: Add any constructor code after initForm call
}
public void OnWeatherChanged( int nTemperature )
{
// nTemperature;
MessageBox.show("got change event"); // Never reaches this point
label1.setText( String.valueOf(nTemperature) );
}
/**
* Form1 overrides dispose so it can clean up the
* component list.
*/
public void dispose()
{
super.dispose();
components.dispose();

// CUnknown iun = (CUnknown)o;
// iun.Release();
IConnectionPoint cp = null;
IConnectionPointContainer container = (IConnectionPointContainer)o;
cp = container.FindConnectionPoint( IWeatherEvents.iid );
cp.Unadvise(cookie);

}

private void button1_click(Object source, Event e)
{
it.setTemperature( (float) 12.3 );
float x = it.getTemperature();
it.DisplayCurrentTemperature();
}

/**
* NOTE: The following code is required by the Visual J++ form
* designer. It can be modified using the form editor. Do not
* modify it using the code editor.
*/
Container components = new Container();
Button button1 = new Button();
Label label1 = new Label();

private void initForm()
{
this.setText("Form1");
this.setAutoScaleBaseSize(new Point(5, 13));
this.setClientSize(new Point(292, 273));

button1.setLocation(new Point(24, 24));
button1.setSize(new Point(136, 23));
button1.setTabIndex(0);
button1.setText("Help me...");
button1.addOnClick(new EventHandler(this.button1_click));

label1.setLocation(new Point(24, 80));
label1.setSize(new Point(168, 32));
label1.setTabIndex(1);
label1.setTabStop(false);
label1.setText("help m. . . . . ");

this.setNewControls(new Control[] {
label1,
button1});
}

/**
* The main entry point for the application.
*
* @param args Array of parameters passed to the application
* via the command line.
*/
public static void main(String args[])
{
Application.run(new Form1());
}
}
Nov 16 '05 #1
2 1718
Any ideas at all?
Nov 16 '05 #2
Does anyone know how this stuff works? Does anyone use it?

A VB client can receive events from the connection point from the .NET
component, but not the VJ++ client.
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mohit Sachdeva | last post by:
Hello folks. I want my app to process windows events first, so that it has some kind of a "global hook". The scenario is - i want my app to process all messages for "F3" key (or any other key for...
4
by: suresh | last post by:
is there any difference between events and multicast delegates. if so how to differentiate. thanx and regards.
3
by: sonu | last post by:
I have created a window application which has two grid we drag and drop from one grid to other. tn i changed that window application into DLL. and called that dll in a web page. grid are...
4
by: VJ | last post by:
Is there a known way to check programatically the List of events that are attached to a control at runtime. Say i need to know if Click event is attached or not for a button? VJ
3
by: VJ | last post by:
I can't find my posting that had replies to events at runtime.. hence I am posting as new. I did earlier read all your replies. Thanks for the information. I still have not tried them. My...
8
by: Mike P | last post by:
How do you get the Windows login and password of the person who is logged in? Is it possible? *** Sent via Developersdex http://www.developersdex.com ***
12
by: VJ | last post by:
Here is a problem that happened about a few times, on non-development Windows XP Tablet PC with SP2, running NET Framework 2.0 and 1.1. The windows application invoking the web service was...
5
by: lamxing | last post by:
Hi, I've come across a strange problem with the WinForm's sizing. I've designed a WinForm and it runs fine on my computer and some other PCs. But when I was trying to run the app under some PCs...
6
by: Bill Nguyen | last post by:
I'm reading a CSV file with the date colum formatted as "YYMMDD" -"070310" when viewed in notepad or similar trext editor. However, in my app, using ODBCReader, the column value becomes "70310"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.