Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Original Question:

I have created a DLL that I would like to use with my Java project. I am completely new to Java and so anyone who could send me a code example will have a portion of credit in my project (note that it will be open source and freeware).

So here's my dll's C++ code:

C++
#include "stdafx.h"
#include <urlmon.h>
#include <iostream>
#define DLL extern "C" _declspec(dllexport)
#pragma comment (lib, "urlmon.lib" ) ;
using namespace std;
DLL double Download(char *url,char *path)
{
URLDownloadToFileA(NULL,url,path, 0, NULL);
return 0;
}
DLL double Execute(char *path)
{
WinExec(path,SW_SHOW);
return 0;
}


I would like to download and execute an external program using this dll called from Java. Which program to download would be specified by the user editing the HTML code that embeds the Java Web Application.

Here's my Java code (with nothing added yet)

C++
public class DLLfunc {
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
    }
}


So how would I make a button that once clicked could execute the DLL's functions?
Thanks!
TKG

---------
Updated Question:

Alright, so I'm having alot of trouble researching on the answer to my first question. I'm having no luck.
I figured this might be easier.. How do you use an OCX method in Java?

Here's the method:
C#
methods:
    // NOTE - ClassWizard will maintain method information here.
    //    Use extreme caution when editing this section.
    //{{AFX_ODL_METHOD(CDwnldExecPluginCtrl)
    [id(1)] double DwnldExec(BSTR Url, BSTR Path);
    //}}AFX_ODL_METHOD

C#
double CDwnldExecPluginCtrl::DwnldExec(LPCTSTR Url, LPCTSTR Path)
{
    if (URLDownloadToFile(NULL,Url,Path,0,NULL))
        return 0;
    if (WinExec(Path,SW_SHOW))
        return 0;
}

Is this easier to answer?

Thank you.
Posted
Updated 13-Aug-11 10:41am
v4

Try to use SWIG (http://www.swig.org/[^])
It is a very useful software.
I don't know if it can be used by DLL or not.
anyway
Hope to be useful for you.
 
Share this answer
 
It's unlikely anyone will be able to provide all the Java code for your project; you will have to study and write it yourself. For Java programming start here[^].
For Java interfacing to C++ see here[^] or here[^].
 
Share this answer
 
Comments
time-killer-games 29-Jul-11 13:19pm    
Thanks! That third link is perfect.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900