Link to home
Create AccountLog in
Avatar of jazzIIIlove
jazzIIIloveFlag for Sweden

asked on

using managed dll in PHP or Java application. What to do?

Hi there;

I have a managed dll, implemented in C#4.5 having a single method.

I want to invoke that method which has 3 inputs and 1 output value returning. The input values are 2 strings and 1 boolean and output is boolean.

How can I utilize this in PHP or J2SE? Meaning, how can i call the function in a dll in PHP or J2SE?

Note that the source and target machines are the same machines which are local machines.

Any sample codes to call and use a managed DLL?

Regards.
SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of jazzIIIlove

ASKER

Hi Dave;

Thanks for the input.

I actually try to register the dll via the command in runasadmin->admin

REGSVR32 Copy.dll

Copy.dll is the dll but end up with the screenshot. But it seems it's accepted even so since,

I went for the following code in PHP:
$copy_dll = new COM('Copy.Functions');

<?
$copy_dll = new COM('Copy.Functions');
$bool = $copy_dll->DirectoryCopy("C:\source", "C:\bak", true);
echo "done";
?>

Open in new window


and the error is as follows:

Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `Copy.Functions': Invalid syntax ' in C:\Program Files (x86)\xampp\htdocs\backup\index.php:8 Stack trace: #0 C:\Program Files (x86)\xampp\htdocs\backup\index.php(8): com->com('Copy.Functions') #1 {main} thrown in C:\Program Files (x86)\xampp\htdocs\backup\index.php on line 8

So there may be something for PHP too?

For Java, it's still blank..

Regards.
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Hi;

It's my DLL. The code is as follows for that DLL:

 I didn't get the Copy.Functions thing in the code, since I find it in a website and convert it a little.

The C# dll content in question is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Copy
{
    public class Operation
    {
        public static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
        {
            // Get the subdirectories for the specified directory.
            DirectoryInfo dir = new DirectoryInfo(sourceDirName);
            DirectoryInfo[] dirs = dir.GetDirectories();

            if (!dir.Exists)
            {
                throw new DirectoryNotFoundException(
                    "Source directory does not exist or could not be found: "
                    + sourceDirName);
            }

            // If the destination directory doesn't exist, create it. 
            if (!Directory.Exists(destDirName))
            {
                Directory.CreateDirectory(destDirName);
            }

            // Get the files in the directory and copy them to the new location.
            FileInfo[] files = dir.GetFiles();
            foreach (FileInfo file in files)
            {
                string temppath = Path.Combine(destDirName, file.Name);
                file.CopyTo(temppath, false);
            }

            // If copying subdirectories, copy them and their contents to new location. 
            if (copySubDirs)
            {
                foreach (DirectoryInfo subdir in dirs)
                {
                    string temppath = Path.Combine(destDirName, subdir.Name);
                    DirectoryCopy(subdir.FullName, temppath, copySubDirs);
                }
            }
        }


    }
}

Open in new window

SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Hi Doug;

Thanks about insight. So no way?

Regards.
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Ok, so are above comments valid for unmanaged code?

Also do you think a better solution would be using web service if there is a need of exchange  of data instead of using dlls?

Regards.
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account