NCryptoki.tlb import results in "Incomplete type is not allowed"

4/19/2012 11:23:54 AM
Gravatar
Total Posts 2

NCryptoki.tlb import results in "Incomplete type is not allowed"

Hi,

We've successfully used NCryptoki in WPF and web services for some time now.

I would now like to create a multi-browser plugin which uses NCryptoki to perform various actions on a USB token plugged into the client's PC.

BTW. I've been able to use NCryptoki in an ActiveX control but that limits us to using Internet Explorer.

To create a multi-browser plugin I've been investigating the FireBreath framework which has a template that creates a VS2010 C++ solution.

 

In my C++ project I've created a SecurityToken class so I have a SecurityToken.h and SecurityToken.cpp.

In SecurityToken.h I have the following import statements:

#import "C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.tlb"
#import "C:\Dev Tools\FireBreath\projects\HelloWorld\Lib\NCryptoki.tlb"

VS2010 creates the NCryptoki.tlh and tli files.

I then define a Cryptoki object:

Cryptoki *cryptoki;

This all compiles.

 

Then in SecurityToken.cpp I try to initialize my cryptoki object:

std::string libPath = "C:\\TempMN\\eTPKCS11.dll";
this->cryptoki = new Cryptoki(libPath);

 

This gives the compilation error:

error C2514: 'NCryptoki::Cryptoki' : class has no constructors

 

The NCryptoki.tlh has the following definitions for the Cryptoki structure:

struct /* coclass */ Cryptoki;
struct __declspec(uuid("7ec26c78-4297-43e0-bdbc-5477362d8c53"))
Cryptoki;
// [ default ] interface _Cryptoki
// interface _Object
// interface ICryptoki

 

I don't know why the interface definitions are commented out. I could uncomment these but the top of the tlh file has a comment telling me NOT to edit this file. Probably because it gets auto generated.

 

It's been years since I wrote any C++ so I'm sure I've made a schoolboy error somewhere, perhaps I'm missing an option in the import statement.

Perhaps what I'm trying to do isn't even possible using NCryptoki.

Any suggestions would be appreciated.

 

Thanks,

Mark


 

 

 

4/19/2012 7:35:37 PM
Gravatar
Total Posts 300
Ugo Chirico http://www.ugochirico.com

Re: NCryptoki.tlb import results in "Incomplete type is not allowed"

Hi,
the COM version doesn't have the constructor with path parameter.
You should use the default constructor and call the method Init:

 this->cryptoki = new Cryptoki();
int ret = this->cryptoki->Init(libPath);

and that's all.

4/20/2012 6:29:45 PM
Gravatar
Total Posts 2

Re: NCryptoki.tlb import results in "Incomplete type is not allowed"

Hi Ugo,

Thanks for your reply.

Unfortunately,

this->cryptoki = new Cryptoki();

still doesn't compile. Error says "Incomplete type is not allowed". Possibly because it doesn't know how much memory to allocate for a Cryptoki object.

One of many things I tried is the following:

//Is this allocating memory for a Cryptoki object?
Cryptoki myCryptokiObj();

//Create a pointer to a Cryptoki object
Cryptoki (*myCryptokiObjPtr)();

//Get address of our allocated Cryptoki object. However this generates the following linker error:
//error LNK2001: unresolved external symbol "struct NCryptoki::Cryptoki __cdecl myCryptokiObj(void)" (?myCryptokiObj@@YA?AUCryptoki@NCryptoki@@XZ) C:\Dev Tools\FireBreath\build\projects\HelloWorld\SecurityToken.obj HelloWorld
myCryptokiObjPtr = &myCryptokiObj; 

int result = myCryptokiObjPtr->Init(libPath);

 

I'm struggling to know what else to try as I don't "speak" C++! :-)

I'm obviously missing something for example, do we need a NCryptoki.lib for the linker?

BTW.  I ran "regasm /tlb /codebase NCryptoki.dll" as mentioned in the VB6 COM part of the documentation.

 

I know this is being cheeky but I don't suppose there is any VS C++ sample code that works having imported NCryptoki.tlb or even a VS C++ project! If I could just work out how to instantiate a Cryptoki object I would hopefully manage the Token and Session objects.

 

Many thanks,

Mark