Вот, смотрите:
Библиотека состоит из нескольких файлов:
CHybridCOM.cpp
// CHybridCOM.cpp : Implementation of CHybridCOM
#include <vector>
#include "stdafx.h"
#include "CHybridCOM.h"
#include "Hybrid.h"
#include "HybridCOMDebug.h"
#include "HybridCOM-int.h"
#define CERT_LENGTH 32768
stKCFunctionsType *kc_funcs;
STDMETHODIMP CHybridCOM::Init()
{
unsigned long rv = 0;
KC_GetFunctionList(&kc_funcs);
rv = kc_funcs->KC_Init();
if (rv) {
KCC_DebugD("Library Init error:\0", 1, rv);
return S_FALSE;
}
kc_funcs->KC_TSASetUrl("http://tsp.pki.gov.kz:80");
KCC_DebugD("Library Init OK.\0", 0, 0);
return S_OK;
}
STDMETHODIMP CHybridCOM::LoadStore(INT storage, BSTR password, BSTR container, BSTR alias)
{
// TODO: Add your implementation code here
unsigned long rv = 0;
KCCAssert(password != NULL, KCR_PARAM_ERROR);
int tmpPasswLen = WideCharToMultiByte(CP_UTF8, 0, password, wcslen(password) + 1, NULL, 0, NULL, NULL);
std::vector<char> tmp_passw(tmpPasswLen + 1);
WideCharToMultiByte(CP_UTF8, 0, password, wcslen(password) + 1, &tmp_passw[0], tmpPasswLen + 1, NULL, NULL);
KCC_DebugD("LoadStore\0", 0, 0);
rv = kc_funcs->KC_LoadStore(storage, &tmp_passw[0], strlen(&tmp_passw[0]), container, (char *)alias);
if (rv) {
KCC_DebugD("LoadStore error:\0", 1, rv);
return S_FALSE;
}
KCC_DebugD("LoadStore OK.\n\0", 0, 0);
return S_OK;
}
и HybridCOM_i.h
// HybridCOM.idl : IDL source for HybridCOM
//
// This file will be processed by the MIDL tool to
// produce the type library (HybridCOM.tlb) and marshalling code.
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(B541AE08-C6D8-4B27-8566-06FD75585250),
dual,
nonextensible,
pointer_default(unique)
]
interface IHybridCOM : IDispatch{
[id(5001)] HRESULT Init();
[id(5004)] HRESULT LoadStore([in] INT storage, [in] BSTR password, [in] BSTR container, [in] BSTR alias);
};
[
uuid(A7B16770-A0B5-4AAE-9FA4-267521C7B038),
version(2.2),
]
library HybridCOMLib
{
importlib("stdole2.tlb");
[
uuid(0F1065E7-5D87-4693-BE33-E42A299D685A)
]
coclass HybridCOM
{
[default] interface IHybridCOM;
};
[
uuid(313E0DB5-7214-4BE2-900F-DC576253EC9F),
version(2.2)
]
enum Hybrid_COLOR
{
GREEN = 0x00000001,
BLACK = 0x00000002,
BLUE = 0x00000004
};
И есть код С#:
using System;
using System.IO;
using System.Windows.Forms;
namespace HybridTest
{
public partial class Form1 : Form
{
public int HybridFlags;
HybridCOMLib.HybridCOM HybridCOMTest = new HybridCOMLib.HybridCOM();
public Form1()
{
InitializeComponent();
tb_pinCode.Text = "12345";
}
private void btn_select_Click(object sender, EventArgs e)
{
uint err;
string errStr;
Stream myStream = null;
string tokens, certAliasesString, filePath = "";
int tokenCount, certCount, storage = 0;
openFileDialogPath.Title = "Выберите серификат-файл";
openFileDialogPath.InitialDirectory = "c:\\K";
openFileDialogPath.RestoreDirectory = true;
if (openFileDialogPath.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream = openFileDialogPath.OpenFile()) != null)
using (myStream) { filePath = openFileDialogPath.FileName; }
}
catch (Exception ex)
{
MessageBox.Show("Ошибка: Не удалось прочитать файл с диска. Original error: " + ex.Message);
}
}
storage = (int)HybridCOMLib.Hybrid_COLOR.GREEN;
HybridCOMTest.LoadStore(storage, tb_pinCode.Text, filePath, "test");
tb_Path.Text = filePath;
certAliasesString = "";
}
}
}
Вопрос тот же... Как в PHP присвоить значение константы их Hybrid_COLOR?
Вот код в PHP:
$tb_pinCODE = 12345;
$filePath = "C:\1.p12";
$outCert = (string) '';
$alias = (string)'sha256';
$kalkanFlags = 0x1;
$PHP_LIB = new COM("KalkanCryptCOMLib.KalkanCryptCOM") ;
$PHP_LIB -> Init();
$storagee = 0x1;
$PHP_LIB ->LoadStore($storagee,$tb_pinCODE,$filePath,'test');
Функции (Init(), LoadStore) видит, а вот задать константу не могу(