Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

How to call methods from dll


10 replies to this topic

rahuld

rahuld
  • Members
  • 15 posts

Posted 11 April 2005 - 18:49

Hi,

I have written one dll which gives me the current processes running.

I try to call that method in Java program thorugh JNI in Installshield. But some how it doesnt get called and I am not able to see the results.

Can you please help in this regard.

Thanks,
Rahul



Silverlay

Silverlay
  • Members
  • 68 posts

Posted 12 April 2005 - 08:13

And why you don't use InstallScript?
Is it necessary to use Java?
In InstallScript it's simple ...
CODE
                    prototype stdcall DllName.SomeFunction();
                               nResult = UseDLL( SUPPORTDIR ^ "DllName.dll" );
                DllName.SomeFunction();
                UnUseDLL( SUPPORTDIR ^ "DllName.dll" );

Bonum initium est dimidium facti

rahuld

rahuld
  • Members
  • 15 posts

Posted 12 April 2005 - 10:13

Thanks for your suggestion.
But basically we need multi platform support and I think Install script do not support Multi Platform.

Let me know if you need any more information.

Thanks,
Rahul

Silverlay

Silverlay
  • Members
  • 68 posts

Posted 12 April 2005 - 10:19

So you usin Universal Installer ... can you put ur code that call's function from dll?
And describe what u want to do exactly ... ))) And i'm try to help you in any case i'm havn't tasks for torday ...
Bonum initium est dimidium facti

rahuld

rahuld
  • Members
  • 15 posts

Posted 12 April 2005 - 10:42

import com.installshield.wizard.*;
import javax.swing.*;
import java.io.*;
import com.installshield.wizard.service.*;
import com.installshield.util.*;
import com.installshield.archive.*;
import com.installshield.wizard.platform.win32.*;
import com.installshield.product.service.product.*;

import java.net.*;



public class GetRegistry extends WizardAction
{

public static final int BUNDLED_JNI_DLL = 1;
private int nativeApproach = BUNDLED_JNI_DLL;

public native String[] checkProcess(String processName, boolean killIt, boolean printOutput);


public void execute(WizardBeanEvent event)
{

PrintWriter print=null;
try
{
print=new PrintWriter(new FileWriter("c:\\testdll.txt"));
print.println("Testing");
print.flush();
}
catch(Exception ex){}
try
{
Win32RegistryService regserv = (Win32RegistryService)getService(Win32RegistryService.NAME);

print.flush();


}
catch( ServiceException se )
{
System.out.println( se.getMessage() );
}
print.println("Entery Point ");
print.flush();

try
{
String fileLocation = "";
if (nativeApproach == BUNDLED_JNI_DLL)
{

print.println("Before source ");
print.flush();

URL url = getResource(getBeanId() + "/TestImp.dll");

print.println("URL" + url);

String tempfile = FileUtils.createTempFile(url,"TestImp.dll");


fileLocation = LibraryLoader.loadLibrary(url, "TestImp.dll");


print.println("tempfile :" +tempfile );

if (url == null)
{
// The following string should be localized.
print.println("Unable to locate NetworkInfo.dll");
print.flush();

}

else {
// Call the native function to get the user name and
// write it to the specified property in the specified
// product bean.


print.println("Testing");
print.flush();

print.println("In exception ");
print.flush();


// Checking for a specific process example
System.out.println("\nchecking for \'Flash.exe\'");
print.println("Before JNI CALL");
print.flush();

String[] ps = checkProcess("Explorer.exe", false, false);

print.println("After JNI CALL");
print.flush();
for(int i = 0; i < ps.length; i++)
{
if(ps[i].equals("Explorer.exe"))
{
System.out.println("Present");

}
System.out.println("Not Present");
}
}
}
}catch(Exception ex)
{
print.println("In exception" + ex);
print.flush();
}

}

public void build( WizardBuilderSupport sup)
{
try
{

sup.putRequiredService( Win32RegistryService.NAME );
if (nativeApproach == BUNDLED_JNI_DLL)
{

String resourceFile = resolveString("$A(IS_HOME)/classes/TestImp.dll");
URL url = new URL(ISMPFileURLStreamHandler.PROTOCOL, "", URLUtils.encode(resourceFile));
sup.putResource(url,getBeanId()+"/TestImp.dll");

String resourceFile_test = resolveString("$A(IS_HOME)/classes/hello.dll");
URL url_test = new URL(ISMPFileURLStreamHandler.PROTOCOL, "", URLUtils.encode(resourceFile_test));
sup.putResource(url_test,getBeanId()+"/hello.dll");


String resourceFile1 = resolveString("$A(IS_HOME)/classes/chkExports.bat");
URL url1 = new URL(ISMPFileURLStreamHandler.PROTOCOL, "", URLUtils.encode(resourceFile1));
sup.putResource(url1,getBeanId()+"/chkExports.bat");

String resourceFile2 = resolveString("$A(IS_HOME)/classes/javac_.bat");
URL url2 = new URL(ISMPFileURLStreamHandler.PROTOCOL, "", URLUtils.encode(resourceFile2));
sup.putResource(url2,getBeanId()+"/javac_.bat");

String resourceFile3 = resolveString("$A(IS_HOME)/classes/Test.h");
URL url3 = new URL(ISMPFileURLStreamHandler.PROTOCOL, "", URLUtils.encode(resourceFile3));
sup.putResource(url3,getBeanId()+"/Test.h");

String resourceFile4 = resolveString("$A(IS_HOME)/classes/Test_run.bat");
URL url4 = new URL(ISMPFileURLStreamHandler.PROTOCOL, "", URLUtils.encode(resourceFile4));
sup.putResource(url4,getBeanId()+"/Test_run.bat");
sup.putClass("Test");

}

}
catch(IOException ie)
{
}

}

}

I have given you total file here. I made the text in Red where I do a call for method which is present in dll.

We have "TestImp.dll" where we have defined this method. Which will return array of the process running on machine. I have put some debug comments in that.

Please let me know if you need any information.

Thanks,
Rahul

Silverlay

Silverlay
  • Members
  • 68 posts

Posted 12 April 2005 - 16:14

Have you build *.h using JNI?
Bonum initium est dimidium facti

Silverlay

Silverlay
  • Members
  • 68 posts

Posted 12 April 2005 - 16:15

QUOTE (Silverlay @ 2005-04-12 16:14)
Have you build *.h using JNI?

I mean
javah -jni <classname>
for ur dll
Bonum initium est dimidium facti

rahuld

rahuld
  • Members
  • 15 posts

Posted 12 April 2005 - 17:28

Yes we build the header file and use it as well. After that we created dll file using CL command.

When this is implemented this is not working.


Silverlay

Silverlay
  • Members
  • 68 posts

Posted 12 April 2005 - 18:27

Then sorry i can't help u here ... every thing seems right for me ... (( if you will have questions in InstallSrcipt based installers i would be more helpful ... ICQ:215869316
Bonum initium est dimidium facti

rahuld

rahuld
  • Members
  • 15 posts

Posted 14 April 2005 - 07:43

Thanks for all your help.

Can you tell me where should I put this question to get my query resolved.

Thanks,
Rahul

Silverlay

Silverlay
  • Members
  • 68 posts

Posted 14 April 2005 - 07:45

If you can skeak russian you can try it here www.rsdn.ru ... but this site www.installsite.net is most strong in installation questions ... and you can also visit community of InstallShield
Bonum initium est dimidium facti