Ishan Rastogi
Ishan Rastogi

Reputation: 830

How to get the handle of SWT control in Mac 64 bit cocoa enviornment?

I have one Eclipse based RCP application in which I need to pass the SWT Control handles to native code to paint something on it. I have the following code to get the handle of any SWT control:

public static int getControlHandle(Control c){
            int handle = 0;
            try {
                if(_isMACOS){
                    if(_viewField== null)
                        _viewField = Control.class.getDeclaredField("view");
                    Object view = _viewField.get(c);
                    if(_idField== null) {
                        Class<?>idClass = Class.forName("org.eclipse.swt.internal.cocoa.id");
                        _idField = idClass.getDeclaredField("id");
                    }
                    handle = _idField.getInt(view);

                }
                else {
                    if(_idField== null)
                        _idField = Control.class.getDeclaredField("handle");
                    handle = _idField.getInt(c);
                }
            }
            catch(Exception e){

            }
            return handle;
    }

_viewField and _idField are java.lang.reflect.Field.

While this works well for Windows and Mac 32 bit but its not working with Mac 64 bit cocoa libs and env. Is there any change in the way to get the handle for 64 bit Mac?

Upvotes: 1

Views: 370

Answers (1)

greg-449
greg-449

Reputation: 111217

On Cocoa 64 bit the id value is a long not an int

Upvotes: 2

Related Questions