Elemental
2013-10-29, 08:27:08
Hallo zusammen,
ich habe eine Fage zu COM Interop und SAFEARRAYs.
Ich habe auf der einen Seite eine COM DLL mit folgendem Interface:
HRESULT WriteSpotxToSPI([in] SAFEARRAY(unsigned char) SpotxContent, [out] SAFEARRAY(unsigned char)* UpdatedContent, [out, retval] VARIANT_BOOL* bSucceeded);
Aufgerufen wird das von einer C# Anwendung über COM Interop:
byte[] bytes = System.IO.File.ReadAllBytes(strSpotFile);
byte[] bytesUpdated = null;
bool bSucceeded = true;
OPTSERVERLib.OptClass optimizer = new OPTSERVERLib.OptClass();
bSucceeded = optimizer.WriteSpotxToSPI(bytes, out bytesUpdated);
Die Frage ist nun, wer muss "byte[] bytes" wieder freigeben?
Bisher wird das in der COM Dll gemacht:
::SafeArrayDestroy(source);
Allerdings kommt es sporadisch zu einer Exception im COM Interop:
System.AccessViolationException
at System.StubHelpers.MngdSafeArrayMarshaler.ClearNative(IntPtr, System.Object ByRef, IntPtr)
at OPTSERVERLib.OptClass.WriteSpotxToSPI(Byte[], Byte[] ByRef)
ich habe eine Fage zu COM Interop und SAFEARRAYs.
Ich habe auf der einen Seite eine COM DLL mit folgendem Interface:
HRESULT WriteSpotxToSPI([in] SAFEARRAY(unsigned char) SpotxContent, [out] SAFEARRAY(unsigned char)* UpdatedContent, [out, retval] VARIANT_BOOL* bSucceeded);
Aufgerufen wird das von einer C# Anwendung über COM Interop:
byte[] bytes = System.IO.File.ReadAllBytes(strSpotFile);
byte[] bytesUpdated = null;
bool bSucceeded = true;
OPTSERVERLib.OptClass optimizer = new OPTSERVERLib.OptClass();
bSucceeded = optimizer.WriteSpotxToSPI(bytes, out bytesUpdated);
Die Frage ist nun, wer muss "byte[] bytes" wieder freigeben?
Bisher wird das in der COM Dll gemacht:
::SafeArrayDestroy(source);
Allerdings kommt es sporadisch zu einer Exception im COM Interop:
System.AccessViolationException
at System.StubHelpers.MngdSafeArrayMarshaler.ClearNative(IntPtr, System.Object ByRef, IntPtr)
at OPTSERVERLib.OptClass.WriteSpotxToSPI(Byte[], Byte[] ByRef)