[Mono-dev] HOW WOULD BE THE CONVERSION OF THIS CODE IN MONO USING PINVOKE? I have problems in the structure.
Justin Cherniak
compwiz312 at gmail.com
Wed Apr 16 18:33:44 EDT 2008
Jose,
You posted to mono-list a few days ago and received a few responses. What
was the problem? Are you getting some error?
If I were to translate it, I would do the following:
struct Request
{
[MarshalAs(UnmanagedType.LPStr)]
public string CategoryID;
[MarshalAs(UnmanagedType.LPStr)]
public string Product_Code;
[MarshalAs(UnmanagedType.LPStr)]
public string Build_Code;
[MarshalAs(UnmanagedType.LPStr)]
public string Manufacturer_id;
public uint Serial_Number;
[MarshalAs(UnmanagedType.LPStr)]
public string Software_Version;
};
public class Test
{
[DllImport("lib.dll")]
public static extern int Manufacture(IntPtr handle, out Request
req);
[DllImport("lib.dll")]
public IntPtr GetHandle(); /* Unmanaged function that returns the
needed
* handle since there is no way
to import
* global variables */
public static void Main(string[] args)
{
Request ID_Device;
int Resultado;
IntPtr handle = GetHandle();
Resultado = Manufacture(piHandle_coin, ref ID_Device);
//*****************problems in &ID_Device STRUCTURE UNMANAGED TO MANAGED AS
PARAMETER
Console.WriteLine("Id Categoria : {0}\n", ID_Device.CategoryID);
Console.WriteLine("Id Product: {0}\n", ID_Device.Product_Code);
Console.WriteLine("Id Build: {0}\n", ID_Device.Build_Code);
Console.WriteLine("Manufacturer: {0}\n",
ID_Device.Manufacturer_id);
Console.WriteLine("Serial Number: {0}\n",
ID_Device.Serial_Number);
Console.WriteLine("Software Revision: {0}\n\n",
ID_Device.Software_Version);
}
}
Enjoy,
Justin
2008/4/16 Jose Castillo Reyes <josecastilloreyes at gmail.com>:
> *I have the following code c++:*
>
> #include <stdlib.h>
> #include <stdio.h>
> extern "C" {
> #include "lib.h"
> }
>
> int iHandle;
>
> struct Request
> {
> char *CategoryID;
> char *Product_Code;
> char *Build_Code;
> char *Manufacturer_id;
> unsigned int Serial_Number;
> char *Software_Version;
> };
>
> int main(void)
> {
> Request ID_Device;
> int Resultado;
>
> Resultado = Manufacture(piHandle_coin, &ID_Device);
> //*****************problems in &ID_Device STRUCTURE 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);
> return 0;
> }
>
> Note:
> ====
> ID_Device is a structure as parameter at Manufacture.
>
> HOW WOULD BE THE CONVERSION IN MONO USING PINVOKE ? I have problems in
> the structure.
>
> THANKS!!
>
> Jose
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080416/6c3dbe49/attachment-0001.html
More information about the Mono-devel-list
mailing list