0

I have a COM dll (native) that I want to use it in my c# project, this dll has a function that get one IntPtr parameter like this :

int GetParameter(out paramCount,IntPtr paramInterfaceArray)

when I pass a IntPtr variable to the function runs without any error, BUT after call function when I want to use paramInterfaceArray to read array of param Interface I got error Access violation executing location . I tried many ways for solve problem but any one works. can anybody help me?

5
  • You need to show us the full C# declaration (DllImport) and also how the native (C/C++, other) side is defined, and what it does (allocation, pointers, etc.) Commented Jan 12, 2019 at 9:42
  • Yes, give us some more info, please. It is very important how the COM dll exposes the array and what it actually returns. .NET knows how to handle COM SafeArrays, but native arrays might require extra marshalling flags / efforts. Commented Jan 12, 2019 at 10:16
  • I have an COM dll that I was written many years ago by some one and no source code is available for COM dll. I just Add reference to the COM dll in Visual Studio, and this is sample code: DLIS dls = new DLIS(); //DLIS is a class from COM dll dls.Open(fileName); ....//SOME OTHER CODE Param list1 = new Param();// Param is an interface from COM dll GCHandle handle1 = GCHandle.Alloc(list1); IntPtr parameter = (IntPtr) handle1; short paramCount ; dls.GetParameters(ref paramCount, parameter );//GetParameter is the function that runs without any error... Commented Jan 12, 2019 at 13:25
  • ...but when I want to access data which parameter refer I got error Access violation executing location Commented Jan 12, 2019 at 13:29
  • First of all, your IntPtr is not defined as out or ref. Pretty hard to get something to return from there. Secondly, you should probably make your function return a SafeArray. However, if you get your way to work, I'd be really interested. Commented Jan 13, 2019 at 6:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.