使用C#中的指针调用c ++函数

时间:2013-09-04 21:21:09

标签: c# c++ struct vb6

我试图在c ++ dll中调用一个函数,但什么也没发生,这就是交易:

该函数定义如下

int BuscaCurpsG(char *archivoOrig, int tipoDocumento, SAFEARRAY **arr_CURPS) ;

和arr_CURPS是这样的结构

typedef struct struct_curps
{
    unsigned short curp[19],
    archivokey[256],
    archivocer[256],
    password[256];
} struct_curps;

我的问题是如何在C#中定义struct数据类型..我在vb6中有一个例子,一切都很好:

 Public Type registro_CURPG
     curp As String * 19
     archivokey As String * 256
     archivocer As String * 256
     password As String * 256
 End Type

并声明函数

Declare Function BuscaCurpsG Lib "sgenc32" Alias "_BuscaCurpsG@12" (ByVal strArchKEY As String, ByVal tipo As Long, ByRef CURPS() As registro_CURPG) As Long

如何在c#中声明我的struct的数据类型?我不能使用固定长度的字符串...

抱歉我的英语,我尽力做到最好。

谢谢。


修改


我宣布了结构

[StructLayout(LayoutKind.Sequential), Serializable]
struct registro_CURPG
{
    [MarshalAs(UnmanagedType.ByValTStr,SizeConst=19)]
    public string curp;

   [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
    public string archivocer;

    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
    public string archivokey;

    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
    public string password;
}

如何在c#中声明该函数?我得到了这个

[的DllImport( “sgenc32.dll”)] private static extern int BuscaCurpsG( string ArchivoOriginal,int TipoDocumento,[In(),Out()] ref registro_CURPG [] CURPS);

有什么东西我不见了?

0 个答案:

没有答案
相关问题