ICustomMarshaler

M

Matthew Wieder

I'm trying to implement uintMarshaler:ICustomMarshaler which will be
used to Marshal a uint as an integer. I have been unable to even find
any sample code anywhere that is helpful, so any help is appreciated. I
must implement:
class uintMarshaler : ICustomMarshaler
{
public static ICustomMarshaler GetInstance( string s )
{
return new uintMarshaler();
}

public object MarshalNativeToManaged(System.IntPtr pNativeData)
{
return null;
}

public System.IntPtr MarshalManagedToNative(object ManagedObj)
{
return new System.IntPtr ();
}

public void CleanUpManagedData(object ManagedObj)
{
}

public int GetNativeDataSize()
{
return 0;
}

public void CleanUpNativeData(System.IntPtr pNativeData)
{
}
}
 
M

Mattias Sjögren

Matthew,
Marshal a uint as an integer.

Why? Can't you just change the parameter type to an int instead? They
are both just 32 bits of data, and wheter it's signed or not is just a
matter of interpretation.

Custom marshaling is only used when you pass pointers to the data
around.



Mattias
 
M

Matthew Wieder

I can't change the C# interface that my class implements. That
interface says the function should return a uint, so that's what my
function returns, but that gets translated into an "unsigned long" by
tlbexp which can't be consumed by VBA. Hence the need to marshal the
uint as an int which tlbexp will then expose as an integer which can be
consumed by VBA.
Can you help?
thanks.
 
M

Mattias Sjögren

Matthew,
I can't change the C# interface that my class implements. That
interface says the function should return a uint, so that's what my
function returns, but that gets translated into an "unsigned long" by
tlbexp which can't be consumed by VBA. Hence the need to marshal the
uint as an int which tlbexp will then expose as an integer which can be
consumed by VBA.
Can you help?


In that case I would declare another, more COM friendly interface and
expose that instead of the original C# interface.



Mattias
 
M

Matthew Wieder

That means we must then maintain two interfaces. Better for code
maintenence is I could implemenet a custom marsheler which would allow
me to maintain one interface.
thanks.
 
Y

Ying-Shen Yu[MSFT]

Hi Matthew,

Since there is only a difference in type (both are 4-bytes), I think you
may try change the IDL definition and re-generate the tlb file directly,
you may get the IDL definition by oleview and re-compile it using midl
compiler. (note, the section"custom" needs be commented). Then you may
reference the modified tlb file in VB6. You make modify the registry to
change the typelib referene to the modified tlb.

Hope it helps.

Best regards,

Ying-Shen Yu [MSFT]
Microsoft community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 

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