I've gotten a bit farther with this... I've been able to define the param as "BYTE**", and given a KB article I found, I had to edit the IL to make the parameter "native int&" rather than "native int". So, now the pointer comes thru properly as an "out IntPtr"...
I'm emulating how the Windows Media Format SDK INSSBuffer::GetBuffer method shows up via COM interop, since I'm similarly passing back audio and video data from a 3rd party DLL. Problem is, when I try and use the IntPtr returned from this COM method, I get this exception: Exception: System.AccessViolationException Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. The pointer I'm returning was allocated using the C++ 'new' operator, so that should be in the unmanaged heap, and I thought that should work in the Bitmap constructor you've mentioned below. The buffer I get back from INSSBuffer::GetBuffer works fine in this situation. Should I instead be using CoAllocTaskMem instead to allocate that buffer in the COM wrapper DLL? -----Original Message----- From: Unmoderated discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Eames, Andrew Sent: Tuesday, June 21, 2005 12:48 PM To: [email protected] Subject: Re: [ADVANCED-DOTNET] [Spam:***** SpamScore] [ADVANCED-DOTNET] COM interop with .NET byte arrays? Unless you have a specific need for COM, you are probably better off wrapping it in managed C++. I *think* that particular bitmap constructor copies the pixels although the documentation doesn't say, so you are probably safe to pass the pointer as an int and cast it to an IntPtr Andrew -----Original Message----- From: Unmoderated discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Kirk Marple Sent: Tuesday, June 21, 2005 3:15 PM To: [email protected] Subject: [Spam:***** SpamScore] [ADVANCED-DOTNET] COM interop with .NET byte arrays? i'm wrapping an unmanaged C++ API in a COM library (using ATL), so i can more easily do interop with C#. one of the APIs i'm wrapping uses a C++ data structure containing an unsigned char* field. I'm looking for the best way to pass this back to .NET. I've gotten it working using a SAFEARRAY, constructed in the ATL DLL, and returned as an Array to .NET, but this entails two extra buffer copies (one into the SAFEARRAY, and one into an unmanaged buffer in .NET for constructing a Bitmap class). Is there an easy way to expose the unmanaged 'unsigned char*' pointer from the ATL DLL (as an IntPtr), so I can use it directly in the Bitmap class constructor? thanks for any help, Kirk -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ Kirk Marple Chief Software Architect, VP of Engineering Agnostic Media, Inc. e: [EMAIL PROTECTED] w: www.agnostic-media.com blog: http://sqljunkies.com/WebLog/kmarple You can get my Digital ID here: https://digitalid.verisign.com/services/client/index.html =================================== This list is hosted by DevelopMentor(r) http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com BEGIN-ANTISPAM-VOTING-LINKS ------------------------------------------------------ Teach CanIt if this mail (ID 4316110) is spam: Spam: http://mail-gw.cognex.com/canit/b.php?c=s&i=4316110&m=9b8f7ff35d96 Not spam: http://mail-gw.cognex.com/canit/b.php?c=n&i=4316110&m=9b8f7ff35d96 Forget vote: http://mail-gw.cognex.com/canit/b.php?c=f&i=4316110&m=9b8f7ff35d96 ------------------------------------------------------ END-ANTISPAM-VOTING-LINKS =================================== This list is hosted by DevelopMentor. http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com
