Re: Need Help declaring parameter variables for DllImport for c-dl
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Mon, 18 Jun 2007 17:47:23 +0200
"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.
.
- Follow-Ups:
- References:
- Need Help declaring parameter variables for DllImport for c-dll fu
- From: Pucca
- Re: Need Help declaring parameter variables for DllImport for c-dll fu
- From: Willy Denoyette [MVP]
- Re: Need Help declaring parameter variables for DllImport for c-dl
- From: Pucca
- Need Help declaring parameter variables for DllImport for c-dll fu
- Prev by Date: VS 2005 Add-In wanted
- Next by Date: Re: Loading EXE in the Application [Assembly]?
- Previous by thread: Re: Need Help declaring parameter variables for DllImport for c-dl
- Next by thread: Re: Need Help declaring parameter variables for DllImport for c-dl
- Index(es):
Relevant Pages
|