Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
please help me
i m importing a an unmanged dll and calling a function in c# code from my unmanged dll but i m facing error
This is my code :--
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.
InteropServices;
using System.IO;

namespace usingdifferentclasses
{
    class greeting
    {
        [DllImport(unmanaged.dll", SetLastError = true)]    // importing dll
        public static  extern int XRay_SearchDevices(out  string[][] pDeviceList, out int pDeviceCount, uint ulFlags);  //function prototype
    }

    class Program
    {
        public delegate int mydelegate(out string[][] pDeviceList, out int pDeviceCount, uint ulFlags);     //declaring delegates
        static  void Main(string[] args)
        {
           
            int a;
            string[][] array;
            greeting g = new greeting();     //creating obj of delegate
          // mydelegate d = new mydelegate(g.XRay_SearchDevices);    //(associating delegate with function)     gives error 

            mydelegate d = new mydelegate(greeting.XRay_SearchDevices);    /// (associating delegate with function)  this works
            d(out  array, out a, 0);  // function is called.
        }
    }
}


the error i get is :An unhandled exception of type 'System.Runtime.InteropServices.MarshalDirectiveException' occurred in program without initialising ourdll.exe

Additional information: Cannot marshal 'parameter #1': There is no marshaling support for nested arrays.

Thanks and Regards

Md.Aasif Eqbal Aslam.
aasifaslamy85@gmai.com
mumbai (india)
Posted
Updated 28-Jan-10 23:21pm

Hi.

It's really true, .Net doesn't support marshaling of nested arrays.

The only way to marshal nested array for you is to
1. Declare params as IntPtrs
2. Allocate memory for them
3. Marshal all data manually

But first, it would be nice to see original definition of your function you are trying to export. Maybe everything isn't so bad..

Regards,
Alexey
 
Share this answer
 
aasif aslam wrote:
Cannot marshal 'parameter #1': There is no marshaling support for nested arrays.


That seems clear enough. You will probably need to write some unmanaged code to handle the call to the DLL, I think this is possible in C# although I have not used it myself.

btw I have placed your code in the correct <pre></pre> tags - looks better doesn't it?
 
Share this answer
 

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