VB.Net to COM marshalling

H

Hemal

I am using a COM interface decalared as follows from VB.Net

interface ISample : IDispatch
{
[id(1), HRESULT Write(long* pBuffer)
}

In VB.Net, I get the address from the call below and pass it to the
"Write"
function which is declared as

Write( ByRef pBuffer as Integer )

.....
Dim ptrBuffer As Integer =
playbackArrayHandle.AddrOfPinnedObject.ToInt32
obj.Write( ptrBuffer )

However, the COM object receives the pointer as a long** or a
pointer-to-pointer-to a long. I understand that if the type was
changed to ByVal this will work. But I cannot change the interface and
I need a pointer to the long. How can I fix this?

Thanks
Hemal
 
K

Ken Tucker [MVP]

Hi,

Why dont you use an inptr instead of integer.

http://msdn.microsoft.com/library/d...us/cpref/html/frlrfsystemintptrclasstopic.asp


Ken
------------------
I am using a COM interface decalared as follows from VB.Net

interface ISample : IDispatch
{
[id(1), HRESULT Write(long* pBuffer)
}

In VB.Net, I get the address from the call below and pass it to the
"Write"
function which is declared as

Write( ByRef pBuffer as Integer )

.....
Dim ptrBuffer As Integer =
playbackArrayHandle.AddrOfPinnedObject.ToInt32
obj.Write( ptrBuffer )

However, the COM object receives the pointer as a long** or a
pointer-to-pointer-to a long. I understand that if the type was
changed to ByVal this will work. But I cannot change the interface and
I need a pointer to the long. How can I fix this?

Thanks
Hemal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top