Hello all.. will appreciate all the help I can get here.... thanks in
advance.
I am using one C++ COM dll under interop in C#. Since this lib is not
supposed to be run in C# I really have no venue for support. And I have
no control on the C++ dll side.
This is the C++ function protype I dig from documentation.
VARIANT_BOOL ReadMemory ( unsigned char* Data, long Size);
C# intellisense show this as
bool ReadMemory (ref byte Data, int Size);
This is what I am trying to do:
byte[] byteImage = (byte[]) SomeObject.Image; //image is basically
raw bmp data
ReadMemory(ref byteImage, byteImage.Length); //here is the problem
the Error is
Argument '1': cannot convert from 'byte[]' to 'ref byte'
Any input regarding this is appreciated. My limitation is that the
image can be quite big ... upto 30KB. And i need to do this with good
performace in mind. So things like converting to string first (I dont
know hoe to do this too) will help but will result to bad performance.
Thank you sir!!!!
>This is the C++ function protype I dig from documentation.
>
[quoted text clipped - 3 lines]
>
>bool ReadMemory (ref byte Data, int Size);
You can modify the interop assembly so the first parameter's type
becomes a byte[] instead and just pass in the array you want. See the
section "Conformant C-Style Arrays" at
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconeditinginteropassembly.asp
Mattias

Signature
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
harishashim@gmail.com - 26 May 2006 03:37 GMT
Wow! I don't even know that this can be done. I learn a new thing
today!!! Thanks so much.
This is the IL before and After
BEFORE
=======
.method public hidebysig newslot virtual
instance bool ReadMemory([in] unsigned int8& Data,
[in] int32 DataSize) runtime
managed internalcall
AFTER
=====
.method public hidebysig newslot virtual
instance bool ReadMemory([in] unsigned int8[] marshal([])
Data,
[in] int32 Size) runtime managed
internalcall
Just after changing and recompile back into interop.xxx.dll, I stumble
a bit since everytime I rebuild the project the interop.xxx.dll is
revert back to its original form. This is probably because VS .NET
recompile the interop dll from original COM dll at every rebuild.
My (temporary) work around to this is to
1. Delete the original refference to the COM dll in refferences part of
explorer window
2. Copy the corrected interop.xxx.dll into output folder (bin\debug)
3. Add interop.xxx.dll refference into my project.
This workaround smell fishie though. I can see a problem already when
building a RELEASE build. I am sure there is a better way to do this.
For instance tell VS.Net to recompile the IL file instead of the
original COM dll.
Further help and advise is appreciated.
Mattias Sjögren - 26 May 2006 19:20 GMT
>This workaround smell fishie though.
There's nothing wrong with it, except perhaps that you should place
the assembly somewhere other than in the bin\debug directory.
Mattias

Signature
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.