1. надо вызвать функцию cr_init. функция в dll сама выделяет память.
2. передать полседний параметр на вход cr_file_get_sign_struct- ref init_struct
Ошибок компиляции нет
cr_file_get_sign_struct function вот эта функция возвращает ошибку — как будто не верно в нее параметры передаются
ТКНИТЕ НОСОМ ГДЕ ОШИБКА В ПЕРЕДАЧЕ ПАРАМЕТРОВ
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
my myclass = new my();
myclass.myfunction();
}
}
public class my
{
const int MASTER_KEY_LEN = 108;
const int ELG_KEY_LEN = 64 + 2;
const int TM_NUMBER_LEN = 8;
const int USER_ID_LEN = 256;
const int COMMENT_LEN = 256; // ???
const int SIGN_LEN = 64; // Pure Signature length, without User ID, its lenght and CRC.
const int HASH_LEN = 32;
const int ERR_NO_SIGN = 11;
struct CR_INIT
{
public IntPtr empty;
}
CR_INIT init_struct = new CR_INIT();
//CR_INIT init_struct = new CR_INIT();
IntPtr ptrparam = IntPtr.Zero;
//int DECL cr_init(int tm_flag, in
// const char *gk, in
// const char *uz, in
// const char *psw, in
// char *tm_number, out
// int *tmn_blen, in,out
// int *init_mode, out
// CR_INIT **init_struct ); out
[DllImport("Bicr_usr.dll")]
static extern int cr_init(
Int32 tm_flag,
string gk,
string uz,
string psw,
out string tm_number,
ref Int32 tmn_blen,
ref Int32 init_mode,
ref IntPtr init_struct);
Насколько я понимаю, CR_INIT* это некий абстрактный handle (члены структуры в пользовательском коде не используются).
Поэтому в управляемом коде его объявлять не надо — там где функция в качестве параметра требует CR_INIT** передавать out IntPtr (или ref — по смыслу), где CR_INIT* — просто полученный IntPtr.
И при передаче строковых я бы везде добавил [MarshalAs(UnmanagedType.LPStr)] — вроде бы по умолчанию строки считаются юникодовыми, а сишная сторона явно хочет char*.