Discussion:
Editing interrop dll type int8&
(too old to reply)
Davy
15 years ago
Permalink
I'm not a very experienced programmer but experienced enough to find out the
only way I could use a com dll supplied by a third party is to edit the
passed parameter type.

In VS2008 I get this...
COMLIB.Decompressor.Decompress(int, ref sbyte) has some invalid arguments...

The function in C++ looks like this :

long Decompress(long lDataLen, signed char * pData)

The function for the dissambled dll looks like this :

Decompress([in] int32 lDataLen,
[in] int8& pData) runtime managed internalcall

What should I put as a parameter, I know I have to change it.
SDK Declaration is like this.
SDK text ****************************************
HRESULT Decompress()
[in] long lDataLen
[in,size_is(DataLen)] char * pData
[out,retval] SHORT * peResult

Remarks
This is called to provide compressed data to this NtlxDecompressor object.
The frame probably got to you via the INtlxDirectClientCallback::OnLiveVideo
of the _INtlxDirectClientEvents::OnLiveVideo event.
NOTE:Those events pass a "long" that is really a byte pointer, so use that
in the event handler; do not save those values for later.

**********************************************
I believe I should change the parameter to Sbyte, I don't feel secure, I'll
need someone to guide me.
Thanks.
Davy
Jeroen Mostert
15 years ago
Permalink
Post by Davy
I'm not a very experienced programmer but experienced enough to find out the
only way I could use a com dll supplied by a third party is to edit the
passed parameter type.
In VS2008 I get this...
COMLIB.Decompressor.Decompress(int, ref sbyte) has some invalid arguments...
long Decompress(long lDataLen, signed char * pData)
Although the signature is misleading, it can still work, depending on where
you get your data to decompress. The function really wants a pointer to the
first byte of the data.

If you are passing in the data from a managed array, you can do this:

byte[] data = new byte[1024];
...
fixed (byte* pData = &data[0]) {
Decompress(data.Length, ref *((sbyte*) pData));
}

If you do want to change the signature and it's realistic to do so (you'll
need to use ILDASM, ILASM and repeat this every time the DLL changes) you
can change it to something like this:

int32 Decompress(int32 lDataLen, [in][out] uint8[] marshal([ + 0]) pData)

It would be this in C# (if you could declare COM imports directly):

int Decompress(int lDataLen, [In, Out, MarshalAs(UnmanagedType.LPArray,
SizeParamIndex = 0)] byte[] pData)

This will allow you to pass managed arrays directly without using unsafe code.

Note that aside from being inconvenient, unmanaged interop can carry a
significant performance penalty. You may want to use C++/CLI to provide your
own managed wrappers around the tricky bits (if it's image data you don't
need to process, for example, you can have C++/CLI write it directly to a
bitmap).
--
J.
Loading...