PDA

View Full Version : [C#]DllImport di dll con strutture


HVDSV
24-11-2008, 17:37
In C++ ho una funzione fatta cosi

void APIENTRY a(int b, struttura_ c){..}

dove struttura_ è

typedef struct struttura_
{
char *primo_C;
bool secondo_C;
} struttura_


Come faccio in C# a importarla ed ad utilizzarla? Come deve essere passato il parametro "struttura_"???

[DllImport("nomedll.dll")]
internal static extern void a(int b, struttura_ c);

Vincenzo1968
24-11-2008, 18:10
Devi definire una struttura dotata degli stessi campi(e nello stesso ordine):


[StructLayout(LayoutKind.Sequential)]
public struct struttura_
{
public String primo_C;
public bool secondo_C;
}

[DllImport("nomedll.dll")]
public static extern void a(int b, struttura_ c);


:bimbo:

DuHarTapt
25-11-2008, 11:53
Una curiosità che ho sempre avuto.
Ma se invece di una struttura avesse dovuto importare un' intera classe avrebbe potuto farlo coś facilmente?

Vincenzo1968
25-11-2008, 15:15
Una curiosità che ho sempre avuto.
Ma se invece di una struttura avesse dovuto importare un' intera classe avrebbe potuto farlo coś facilmente?

Non ne sono sicuro al 100% ma credo che non si possa fare.

:bimbo:

Hardware Upgrade Forum Database Error
Database Error Database error
The Hardware Upgrade Forum database has encountered a problem.

Please try the following:
  • Load the page again by clicking the Refresh button in your web browser.
  • Open the www.hwupgrade.it home page, then try to open another page.
  • Click the Back button to try another link.
The www.hwupgrade.it forum technical staff have been notified of the error, though you may contact them if the problem persists.
 
We apologise for any inconvenience.