[Mono-dev] PROBLEMS CALLING STRUCTURES UNMANAGED TO MANAGED AS PARAMETER USING MONO.

Jonathan Pryor jonpryor at vt.edu
Sat Apr 12 03:08:29 EDT 2008


On Fri, 2008-04-11 at 19:01 -0500, Jose Castillo Reyes wrote:

> struct Request 
> { 
>     char *CategoryID;   
>     char *Product_Code; 
>     char *Build_Code; 
>     char *Manufacturer_id; 
>     unsigned int Serial_Number; 
>     char *Software_Version; 
> };

        struct Request {
                public IntPtr CategoryID, ProductCode, BuildCode,
                        Manufacturer_id;
                public uint Serial_Number;
                public IntPtr Software_Version;
        }

> int main(void)
> {
>     Request ID_Device;  
>     int Resultado;
> 
>     Resultado = Manufacture(piHandle_coin, &ID_Device);

        class Test {
                [DllImport ("YourLib.dll")]
                static extern int Manufacture(/*typeof piHandle_coin*/,
                        out Request request);
                
                static void Main (string[] args)
                {
                        Request ID_Device;
                        int Resultado = Manufacture (piHandle_coin, 
                                out ID_Device);

>   //*****************problems in &ID_DEVICE STRUCTURES UNMANAGED TO
> MANAGED AS PARAMETER
> 
>     printf("Id Categoria : %s\n",ID_Device.CategoryID);
>     printf("Id Product: %s\n",ID_Device.Product_Code);
>     printf("Id Build: %s\n",ID_Device.Build_Code);
>     printf("Manufacturer: %s\n",ID_Device.Manufacturer_id);
>     printf("Serial Number: %u\n",ID_Device.Serial_Number);
>     printf("Software Revision: %s\n\n",ID_Device.Software_Version);

                        Console.WriteLine (
                                Marshal.PtrToString
                                (ID_Device.CategoryID));
                        // ...
                }
        }

See also:

        http://www.mono-project.com/dllimport

 - Jon




More information about the Mono-devel-list mailing list