INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Dll reference

Dll reference

(OP)
Hi all!

Normally to use another dll within my java API I use the COM wrapper, but is there another way to do so? I used a dll and go the error 'object can only be invoked through an interface reference'. If I use VB to reference to this dll I get no error. What is the difference between this two ways? Is it possible to 'reference' in j++? thanxs.

cheers,
alej

RE: Dll reference

(OP)
Got the answer myself and wanted to share it since it really was a big problem for me.

Out of the MSDN: you must use one of its interfaces to manipulate an instance of the COM class. COM does not support accessing properties or methods on a class independently from its interfaces!

which means the following:

import comserver.IComBeeper;  
import comserver.CComBeeper;

IComBeeper testBeep = (IComBeeper)new CComBeeper();
int myTone = testBeep.getSound();
testBeep.putSound(64);
testBeep.Beep();

and NOT:

CComBeeper testBeep = new CComBeeper();
int myTone = testBeep.getSound();

which is what I was doing. It compiles but it doesn't work after.

cheers,
alej

RE: Dll reference

Hi Almoes
         Iam having problem with visual J++ 6.0
I have a dll file named trimSDK.dll in VB.
I want to include this library inside J++ 6.0
and use the COM objects in Java.
        I have a inbuilt library called trim sdk
in J++ 6.0 but iam unable to get the output
when i use the COM objects

import trimsdk.*;

IDatabase d = (IDatabase) new Database();
d.setId("45");
System.out.println(d.getName());

  Iam not getting the output though it compiles..
It is urgent!!! Please help.
Madhan

RE: Dll reference

(OP)
Hello Madhan,

I try to help...did you use the 'COM wrapper' to add the classes to your project?

RE: Dll reference

Hi Almoes
    No i didnt use the COM Wrapper... i used
the project properties window to add the classes

RE: Dll reference

Hi Almos
   Good to see u online..can u give me ur
chat id for me to include yours..this is
very important to me...please

RE: Dll reference

(OP)
never used the chat... :-[
Remove the classes from the project and use the 'COM wrapper' sometimes to use the dlls you need other special microsoft classes for compatibility, and the wrapper includes them directly.

cheers,
alej

RE: Dll reference

I have not used the COM Wrapper..and iam very
new to J++ 6.0...
       Once i click the COM wrapper button it
gives the set of available libraries....do
u ask me to select the trimSDK library from
that

RE: Dll reference

(OP)
Right. If your library is registered in your machine, you will be able to use it. So use the browse button to locate your dll.

RE: Dll reference

Let me be more specific.

I have "trimSDK.dll" in VB

It has classes written in VB. I dont know
whether it is COM dll or not.It works well
in VB .

I have the same library in J++ 6.0
as "trim sdk library" which i found
in the COM classes message box itself.
So all i did is i enabled that and
it gave me number of .java files which
i could view it displayed under the
project.Finally i built it and coded:

import trimsdk.*;

IDatabase d = (IDatabase) new Database();
d.setId("45");
System.out.println(d.getName());

it should execute as "DemoDb" which is
what executed in VB.

But i found in the source code of Database.java
public getName() throws COMFailure exception
{
}

public setid() throws COMFailure exception
{
}


so when i compile the above code in console
applicatio. i get "COM Exception"

RE: Dll reference

(OP)
I am confused now, you have two dlls? I was using all kinds of dlls with j++ and the 'com wrapper' no matter in which language they are written in.

RE: Dll reference


Iam sorry for that...

My fellow person uses "trim sdk library"
in VB to perform the code which i qouted
above.(System A)
His coding (I cldnt remember as i
dont know VB) was like this

Dim d as trimSDK.database

d.id="45"
print (d.Name)

so the output in his system was "demoDB"


(System B)
Now i have to use J++ 6.0 to do the same
coding in Java.I have the  "trim sdk library"
in J++  
       Do tell me what to do

RE: Dll reference

(OP)
Ah! ok open a new project (whichever type you need) in j++. Then go to COM wrapper and add trimSDK.dll, which it should be registered in your developing machine. Then right the followinig code:

import trimSDK.*;

trimSDK.IDatabase d = (trimSDK.IDatabase) new trimSDK.Database();
d.setId("45");
System.out.println(d.getName());

Make sure that the name of the dll and classes are well written because its case sensitive. And check after the com wrapper adds the classes to the project that the interfaces are defined (IDatabase interface, maybe it has a different name).



RE: Dll reference

oh ok

 Now i have some questions....

 Earlier my team leader asked me to convert
the trimsdk.dll(In VB) to Java.
  So i found "EZJCom" software in the website
that transferred trimsdk.dll to Jtrimsdk.dll
and with java classes.
    Are u sure that this is not required
in J++ 6.0...

RE: Dll reference

(OP)
I never had to use anything like that before, the COM wrapper was creating the java classes of all dlls i used

RE: Dll reference


Ok.


1.
as i already written above:


public getName() throws COMFailure exception
{
}

public setid() throws COMFailure exception
{
}

these two methods are found in Databases.java
and they just return exception which i used the
code below


import trimSDK.*;

trimSDK.IDatabase d = (trimSDK.IDatabase) new trimSDK.Database();
d.setId("45");
System.out.println(d.getName());



But i didnt use COM wrapper....do u now
think that it wld be solved if i
use COMWrapper


  After adding in COM wrapper...
does the trimSDK package show
all the java classes in object
browswer

RE: Dll reference

Ok.


1.
as i already written above:


public getName() throws COMFailure exception
{
}

public setid() throws COMFailure exception
{
}

these two methods are found in Databases.java
and they just return exception which i used the
code below


import trimSDK.*;

trimSDK.IDatabase d = (trimSDK.IDatabase) new trimSDK.Database();
d.setId("45");
System.out.println(d.getName());



But i didnt use COM wrapper....do u now
think that it wld be solved if i
use COMWrapper


  After adding in COM wrapper...
does the trimSDK package show
all the java classes in object
browswer

RE: Dll reference

(OP)
As I told you, I use the COM wrapper. And yes, when you add the dll you will be able to see the java file and the proper names of the classes and interfaces because this could be your problem.

RE: Dll reference

Thank u very much almose
Iam leaving now...
I wld post u again if
i get any problme...
 I request u to reply
as soon as possible
as my deadline is
nearing...may be
tomorrow i wld post
  Thank u
  Bye
  Madhan

RE: Dll reference

(OP)
I will try to help, depends on work load.

cheers,
alej

RE: Dll reference

Hi almoes
   Thank u very much....it is working
now..but iam not able to print the
result in applet...

import trimsdk.*;
public class Class1
{

public static void main (String[] args)
{
    String s="";
    trimsdk.IDatabase d = (trimsdk.IDatabase) new trimsdk.Database();
    d.setId("45");
    s=d.getName();
    System.out.println(s);
    //System.out.println("Hiii");
    
    }
}


The above coding works well but not in applet.
I couldnt get the same result in applet...


import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import trimsdk.*;

public class Applet1 extends Applet
{
    trimsdk.IDatabase d = (trimsdk.IDatabase) new trimsdk.Database();
    String s;
        
    
    public void init()
    {                    
        d.setId("45");
    }
    
    public  void paint(Graphics g)
    {
        s=d.getName();
        g.drawString(s,100,100);
    }
    
}


The above code doesnt print anything....
Please do reply me
 Madhan

RE: Dll reference

(OP)
I am afraid I can't help you with applets, sorry.

cheers,
Alej

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close