
Marshal problem with pointers to structures
There are many problems...
- the code you posted NEVER allocates 'lcptrCrypt'
- for AllocCoTaskMem( 4 ), this is NOT the size of WFSXDATA.
- memory leaks / overwrites.
The basic marshaling of WFSPINCRYPT & WFSXDATA could be:
// ===================================================================
Type typXD = typeof( WFSXDATA );
int sizeXD = Marshal.SizeOf( typXD );
WFSPINCRYPT lcsttCrypt = new WFSPINCRYPT();
lcsttCrypt.lpsKey = new String( ' ',256 );
lcsttCrypt.lpsStartValueKey = new String( ' ',256 );
lcsttCrypt.lpxCryptData = Marshal.AllocHGlobal( sizeXD );
lcsttCrypt.lpxKeyEncKey = Marshal.AllocHGlobal( sizeXD );
lcsttCrypt.lpxStartValue = Marshal.AllocHGlobal( sizeXD );
WFSXDATA lcsttCryptData = new WFSXDATA();
lcsttCryptData.lpbData = new String( ' ', 256 );
lcsttCryptData.usLength = 256;
Marshal.StructureToPtr( lcsttCryptData, lcsttCrypt.lpxCryptData, false );
WFSXDATA lcsttKeyEncKeys = new WFSXDATA();
lcsttKeyEncKeys.lpbData = new String( ' ', 256 );
lcsttKeyEncKeys.usLength = 0;
Marshal.StructureToPtr( lcsttKeyEncKeys, lcsttCrypt.lpxKeyEncKey, false );
WFSXDATA lcsttStartValue = new WFSXDATA();
lcsttStartValue.lpbData = new String( ' ', 256 );
lcsttStartValue.usLength = 0;
Marshal.StructureToPtr( lcsttStartValue, lcsttCrypt.lpxStartValue, false );
// ===================================================================
but I don't understand all the rest of your code
beyond your line:
lcsttCrypt.wMode = PIN_MODEENCRYPT;
.... ???? ....
And you didn't post the C/C++ source & documentation,
so there could still be MANY hidden translation errors.
--
Thomas Scheidegger - MVP .NET - 'NETMaster'
http://www.cetus-links.org/oo_dotnet.html - http://dnetmaster.net/
Quote:
> I have some problems passing parameters to a function
> defined in a dll written in C.
> See the attached file to a description of my problem ...