Marshal problem with pointers to structures 
Author Message
 Marshal problem with pointers to structures

Hi,
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 ...

Thanks !!!

  question.txt
3K Download


Sat, 07 May 2005 06:35:23 GMT  
 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 ...



Sat, 07 May 2005 07:14:30 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Marshaling a structure containing a aray of different structures

2. How to marshal pointer to pointer to struct

3. Converting byte[] to structure without Marshal?

4. Marshaling structures with arrays

5. Marshal..marshaling..

6. Marshaling an interface pointer.....

7. How to Marshaling COM interface pointers ?

8. Problems assigning structure members to pointers

9. problem with pointer to structure

10. Please help solve a problem that deal with pointer to structure

11. Problem with pointers to structures...

12. SUUMMARY - my structure and pointer problems cured.

 

 
Powered by phpBB® Forum Software