Re: Need Help declaring parameter variables for DllImport for c-dl

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"Pucca" <Pucca@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:8CC5707C-00A1-432B-8A0A-6ACD0045B27E@xxxxxxxxxxxxxxxx
Hi Willy ,
What you said about the nSize and nLength makes a lot of sense. You're also
right about the pointer to the encoded data pointed by a pointer in the Blob
struc. However, the length of the data is not return by AsnExtractData(code
listed below).
I am getting compliation error with my current code below. I'm getting
error message below. Can you see what I need to correct here? Thank you.

- cannot convert from 'ref System.IntPtr' to 'ref UnityLib.CUnityDS.Blob'
- The best overloaded method match for
UnityLib.CUnityDS.LibWrap.EncodeAsnUser(ref UnityLib.CUnityDS.Blob,
UnityLib.CUnityDS.CUserContextData)' has some invalid arguments

int dataSize = 512; // assume 512 byte buffer
IntPtr pBlob = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(CUnityDS.Blob)));
IntPtr pData = Marshal.AllocHGlobal(dataSize );
//CUnityDS.Blob blob = new CUnityDS.Blob();
blob.nSize = dataSize ;
blob.pData = pData;
Marshal.StructureToPtr(blob, pBlob, true);
CUnityDS.LibWrap.EncodeAsnUser(ref pBlob, userContextData);
// check return value from function
// and proceed is success...
blob = (CUnityDS.Blob)Marshal.PtrToStructure(pBlob, typeof(CUnityDS.Blob));
// assuming nLength is the size in bytes returned in the buffer pointed to
by pData!!
byte[] meetingBlob = new byte[blob.nLength];
Marshal.Copy(blob.pData, meetingBlob, 0, blob.nLength);
// use data in meetingBlob here...
// Free allocated memory!
Marshal.FreeHGlobal(pBlob);
Marshal.FreeHGlobal(pData);

-- Blob *
AsnExtractData( AsnData *pAsn )
{
Blob *p;

if ( pAsn == NULL )
return NULL;

p = pAsn->pBlob;
pAsn->pBlob = NULL;

return p;
}
Thanks.


UnityLib.CUnityDS.LibWrap.EncodeAsnUser(ref UnityLib.CUnityDS.Blob,
UnityLib.CUnityDS.CUserContextData)' has some invalid arguments

should read:

UnityLib.CUnityDS.LibWrap.EncodeAsnUser(ref IntPtr,
UnityLib.CUnityDS.CUserContextData)' has some invalid arguments

Don't know who has written the C++ function, I would definitely ask for a rewrite, anyway it needs to return the length of the Data in the blob, otherwise there is no way to correctly marshal the data back at the caller side.

Willy.

.



Relevant Pages

  • Re: Need Help declaring parameter variables for DllImport for c-dl
    ... and it does returns the nLength, data length when it returns encoding data ... into the blob. ... It doesn't like the pBlob that I'm declaring and passing. ... right about the pointer to the encoded data pointed by a pointer in the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Need Help declaring parameter variables for DllImport for c-dl
    ... right about the pointer to the encoded data pointed by a pointer in the Blob ... AsnExtractData(AsnData *pAsn) ... if (!AsnWriteGeneralString(pAsn, EMPTY_STRING)) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: help please!
    ... The first parameter to CertGetCertificateContextProperty should be a pointer ... You're passing a handle to a cert store. ... error GetLastError would give you, but I'd be willing to bet that it's ... I'm not sure what you're trying to do with the blob pointer you're passing ...
    (microsoft.public.platformsdk.security)
  • Re: "trivial question"? ;-)
    ... BLOB, is valid. ... and the other is BYTE* pointer to actual data. ... I have a problem with SafeArray, as I would need to convert the ... (which may include "generic binary data") ...
    (microsoft.public.win32.programmer.ole)
  • Re: "trivial question"? ;-)
    ... BLOB, is valid. ... and the other is BYTE* pointer to actual data. ... This latter pointer must be allocated with CoTaskMemAlloc by one ... PROPVARIANT, use PropVariantClear. ...
    (microsoft.public.win32.programmer.ole)