|
hello,
I am having some complications in calling a function of an existing dll from java.would u please give me a small bit of coding to solve above problem in general.
How can I compile a c file into dll using microsoft compiler please note that I don't have vc++ installed on my system.I got a command for that but I am not able to compile.Do I need to set any class path for that.
thanking u
Seshu
|
|
|
|
|
Hello,
I can run the code as an example. However, when I include the class and DLL in my JBuilder6 project, I get the following error:
java.lang.UnsatisfiedLinkError: initialize
at lpsemail.MyWindow.initialize(Native Method)
at lpsemail.MyWindow.addNotify(MyWindow.java:46)
It would seem that it cannot find the initialize procedure in the DLL. It can find the DLL itself, or I would get a "LoadLibrary" error. Do I have to include the path to the DLL in my "path" variable or my "classpath" variable??
Help would be most appreciated.
Thanks,
|
|
|
|
|
In constructor of dll type some code like
cout<<"in dll";
and then try. If java console window print this message then it means that dll is loaded but java is unable to execute your native function. Check carefully your method name in dll code. It must match with method name in java generated header file.
|
|
|
|
|
If you have created your own dll then I can give you one reason for this error.
Some times this error message is given when the header file included does not exist.
ex:
#include "NativeApp.h"
/*is inside the *.cpp file but it should be */
#include "NativeDllApp.h"
Hope this helps ;)
|
|
|
|
|
copy ur dll in system file
|
|
|
|
|
Tab Key doesn't seems to work in explorer. Is there anyway for this ?
Thanks in advance
|
|
|
|
|
What happens if MyWindow is in package? Eg utils.MyWindow
What should i need to change?
|
|
|
|
|
I wonder if it is possible to add a MFC graphic object in a Java application.
Any idea, any code sample ?
Thanks
|
|
|
|
|
Thankyou for the wonderful artical MR Davanum Srinivas ,
I would like to know how to add the DWebBrowserEvents such as BeforeNavigate,NavigateComplete,StatusTextChange, and also i tryied to get the GetLocationURL but i am able to get it how to get please help me to solve .
Thankyou
|
|
|
|
|
I need to embed Word Application instead of IE within Java Program. Can anybody help me to understand how can i modify this program to do it.
Anita Mehta
|
|
|
|
|
I didn't try this, but saw this link that might help you.
http://www.geocities.com/SiliconValley/Orchard/6171/JAVA2COM.htm
Mark
|
|
|
|
|
|
Hi all,
I'm a newbee in this field. I wanna call the dll made in VB from my Java code. I don't wanna use the third party s/w available like Bridge2java, J-Integra etc because of Licensing Problem.
Is there any way around ??
Any kind of sample code to accomplish this will be extremly helpfull.
Thanx in Advance .
Eagerly waiting for Reply
Regards
Anshu
|
|
|
|
|
Hi
You can call a dll made in vb by wrapping it in another dll made in c++ and invoking the c++ dll using dll. I tried it, but got stuck at a point. the problem is that the call from java to the c++ dll works fine but when the c++ dll call the dll made in vb an error occurs saying that "an error occured while accesing the native code outside VM". which is quite natural as I am just loading the c++ dll in the java code. you will get a code sample at http://www.codeproject.com/dll/ and the title is "Calling a VB ActiveX DLL from a MFC Client" Let me now if there is any further success.
sags
|
|
|
|
|
Hi
I used JNI to call a c++ DLL from java, and let the DLL to call vb control. It works perfectly. I'll write an article and post the sample here soon.
George
|
|
|
|
|
Hi George !
If you have that artical ready can you pl. send it across .Iam in the same situation accesing com coponent from java..If it is taking time you can mail me at kovesr75@yahoo.com
thanks
KS
|
|
|
|
|
The application runs fine, however the moment i close the java window pane or when u do System.exit(0) to exit the process, i get the following error:
This program has performed an illegal operation and will be shut down.
If i click on the Details>> button i get the foloowing decription :
JAVA caused an invalid page fault in
module KERNEL32.DLL at 0157:bff79fa4.
Registers:
EAX=00000000 CS=0157 EIP=bff79fa4 EFLGS=00000246
EBX=000001e0 SS=015f ESP=08f7fb80 EBP=08f7fc6c
ECX=00413e50 DS=015f ESI=653c6278 FS=55af
EDX=00413f84 ES=015f EDI=00413c80 GS=0000
Bytes at CS:EIP:
ff 76 04 e8 3d a2 ff ff 5e c2 04 00 56 8b 74 24
Stack dump:
653c6278 65351847 653c6278 00413c80 00413f58 000001e0 653517cc 00413c80 090ef29c 5f3ed308 00000000 5f3e5adc 00413f58 5f3ed6d8 5f3e172a 5f3ed308
Can anybody help me out on this ?
Thank u,
G-
|
|
|
|
|
Hi
When i run this program on some windows 98 Systems i get an error
java.lang.UnsatisfiedLinkError: C:\my\MyWindow.dll: A device attached to the system is not functioning
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1319)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1243)
at java.lang.Runtime.loadLibrary0(Runtime.java:470)
at java.lang.System.loadLibrary(System.java:768)
at MyWindow.<clinit>(MyWindow.java:13)
Exception in thread "main" Normal Termination
what could be the possible reason for the error
im using jdk1.2.2.
Krithi
|
|
|
|
|
hi could someone tell me how can i set up a java client to call web service implemented with Microsoft SOAP toolkit
thx
|
|
|
|
|
HI. This is really cool.
My question is in regards to using this snippet inside of a JInternalFrame.
I would like to place this Canvas on a JInternalFrame; but when it runs I get a fatal error that crashes the jvm. Any ideas as to what i need to change?
Thanks.
Scott
|
|
|
|
|
Hi,
Sorry, I am not going to give you the answer. I also, got the same problem like you. Have you got any solution for the problem that you mentioned. I Will be happy to receive your solution.
Thanks.
Soundari.R
|
|
|
|
|
Dear Davanum Srinivas :
the programe is very good.I want to show the other URL.i do like that.but it is not work.
would you tell me?
the function is:
JNIEXPORT void JNICALL Java_MyWindow_showURL
(JNIEnv *, jobject, jstring strURL)
{
CComVariant ve;
CComVariant vurl(strURL);
#pragma warning(disable: 4310) // cast truncates constant value
spBrowser->put_Visible(VARIANT_TRUE);
#pragma warning(default: 4310) // cast truncates constant value
spBrowser->Navigate2(&vurl, &ve, &ve, &ve, &ve);
}
thank you!wait fou you!
yours
|
|
|
|
|
I modified the source code of MyWindow.java and MyWindow.CPP of Davanum Srinivas to support the method
// native entry point for showing a URL
public native void showURL(String strURL);
The new files are:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.peer.*;
import sun.awt.*;
public class MyWindow extends Canvas
{
static
{
// Load the library that contains the JNI code.
System.loadLibrary("MyWindow");
}
// native entry point for initializing the IE control.
public native void initialize(int hwnd, String strURL);
// native entry point for showing a URL
public native void showURL(String strURL);
// native entry point for resizing
public native void resizeControl(int hwnd, int nWidth, int nHeight);
// Returns the HWND for panel. This is a hack which works with
// JDK1.1.8, JDK1.2.2 and JDK1.3. This is undocumented. Also
// you should call this only after addNotify has been called.
public int getHWND()
{
int hwnd = 0;
DrawingSurfaceInfo drawingSurfaceInfo = ((DrawingSurface)(getPeer())).getDrawingSurfaceInfo();
if (null != drawingSurfaceInfo)
{
drawingSurfaceInfo.lock();
Win32DrawingSurface win32DrawingSurface = (Win32DrawingSurface)drawingSurfaceInfo.getSurface();
hwnd = win32DrawingSurface.getHWnd();
drawingSurfaceInfo.unlock();
}
return hwnd;
}
public void addNotify()
{
super.addNotify();
m_hWnd = getHWND();
initialize(m_hWnd, m_strURL);
}
String m_strURL = "http://www.javasoft.com";
int m_hWnd = 0;
public static void main( String[] argv )
{
Frame f = new Frame();
f.setLayout(new BorderLayout());
f.setTitle("Internet Explorer inside Java Canvas");
MyWindow w = new MyWindow();
if(argv.length>0)
w.m_strURL = argv[0];
String strText = "URL:" + w.m_strURL;
f.add(w,BorderLayout.CENTER);
f.add(new Label(strText),BorderLayout.NORTH);
f.setBounds(300,300,500,300);
f.setVisible(true);
}
public void setSize( int width, int height )
{
super.setSize(width,height);
if(m_hWnd!=0)
resizeControl(m_hWnd, width, height);
}
public void setSize( Dimension d )
{
super.setSize(d);
if(m_hWnd!=0)
resizeControl(m_hWnd, d.width, d.height);
}
public void setBounds( int x, int y, int width, int height )
{
super.setBounds(x,y,width,height);
if(m_hWnd!=0)
resizeControl(m_hWnd, width, height);
}
public void setBounds( Rectangle r )
{
super.setBounds(r);
if(m_hWnd!=0)
resizeControl(m_hWnd, r.width, r.height);
}
}
#include <windows.h>
#include <assert.h>
#include <process.h>
#include "MyWindow.h"
// Includes for ATL
#pragma comment(lib,"atl.lib")
#include <atldef.h>
#define _ATL_DLL_IMPL
#include <atliface.h>
#include <atlbase.h>
#include <exdisp.h>
// Structure for Thread Parameters.
typedef struct {
char szURL[1024];
HWND hwnd;
} ThreadParam;
HWND hwndChild;
// Helper functions.
VOID CreateIEControl(ThreadParam *);
static void WINAPIV StartATL(LPVOID);
// native method for initializing the control.
JNIEXPORT void JNICALL Java_MyWindow_initialize
(JNIEnv *pEnv, jobject, jint hwndIn, jstring string)
{
// Fill up the params.
const char *str = pEnv->GetStringUTFChars(string, 0);
ThreadParam *pThreadParam = new ThreadParam;
pThreadParam->hwnd = (HWND) hwndIn;
strcpy(pThreadParam->szURL,str);
pEnv->ReleaseStringUTFChars(string, str);
// Launch the Thread.
_beginthread(StartATL, 0, pThreadParam);
}
JNIEXPORT void JNICALL Java_MyWindow_showURL
(JNIEnv *pEnv, jobject, jstring string)
{
const char *str = pEnv->GetStringUTFChars(string, 0);
IUnknown *pUnk = NULL;
AtlAxGetControl(hwndChild,&pUnk);
printf("Create AtlAxWin Done...[0x%x]\n",pUnk);
// get an interface to set the URL.
CComPtr<iwebbrowser2> spBrowser;
pUnk->QueryInterface(IID_IWebBrowser2, (void**)&spBrowser);
if (spBrowser)
{
CComVariant ve;
CComVariant vurl(str);
#pragma warning(disable: 4310) // cast truncates constant value
spBrowser->put_Visible(VARIANT_TRUE);
#pragma warning(default: 4310) // cast truncates constant value
spBrowser->Navigate2(&vurl, &ve, &ve, &ve, &ve);
}
pEnv->ReleaseStringUTFChars(string, str);
}
// Thread for creating the control
void WINAPIV StartATL(LPVOID lpVoid)
{
ThreadParam *pThreadParam = (ThreadParam *)lpVoid;
CreateIEControl(pThreadParam);
delete pThreadParam;
MSG msg;
// Windows message loop.
while(GetMessage(&msg, NULL, NULL, NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
// Creates IE control
VOID CreateIEControl(ThreadParam *pThreadParam)
{
AtlAxWinInit();
printf("Create AtlAxWin Begin...[0x%x][%s]\n",pThreadParam->hwnd,pThreadParam->szURL);
// In the 2nd Param you can use ProgID or UUID of any activex control.
hwndChild = ::CreateWindow("AtlAxWin",
"Shell.Explorer.1",
WS_CHILD|WS_VISIBLE,
0,0,0,0,
pThreadParam->hwnd,NULL,
::GetModuleHandle(NULL),
NULL);
IUnknown *pUnk = NULL;
AtlAxGetControl(hwndChild,&pUnk);
printf("Create AtlAxWin Done...[0x%x]\n",pUnk);
// get an interface to set the URL.
CComPtr<iwebbrowser2> spBrowser;
pUnk->QueryInterface(IID_IWebBrowser2, (void**)&spBrowser);
if (spBrowser)
{
CComVariant ve;
CComVariant vurl(pThreadParam->szURL);
#pragma warning(disable: 4310) // cast truncates constant value
spBrowser->put_Visible(VARIANT_TRUE);
#pragma warning(default: 4310) // cast truncates constant value
spBrowser->Navigate2(&vurl, &ve, &ve, &ve, &ve);
}
}
// native method for handling resizes.
JNIEXPORT void JNICALL Java_MyWindow_resizeControl
(JNIEnv *, jobject, jint hwndIn, jint width, jint height)
{
HWND hwnd = (HWND) hwndIn;
RECT rc;
if(hwnd!=NULL)
{
::GetWindowRect(hwnd,&rc);
HWND hwndChild = GetWindow(hwnd, GW_CHILD);
printf("got resize (0x%x,%d,%d)\n",hwndChild,width,height);
::SetWindowPos(hwndChild,NULL,0,0,rc.right-rc.left,rc.bottom-rc.top,SWP_NOZORDER|SWP_NOACTIVATE|SWP_SHOWWINDOW|SWP_NOMOVE);
}
}
|
|
|
|
|
how to access ACTIVEX EXE and DLL(3rd party tools)in java programming
|
|
|
|
|
You can use the following tools to use ActiveX componment as java beans.
http://www.jguru.com/faq/view.jsp?EID=135081
|
|
|
|
|