Click here to Skip to main content
15,794,275 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

I am importing External DLL into my Application. All other function in DLL are working fine but one is not and giving Following error: "
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

My computer is 64 bit.

And my code is
Impoting DLL
[DllImportAttribute("libMPSSE.dll", EntryPoint = "SPI_ChangeCS", CallingConvention = CallingConvention.Cdecl)]
static extern FTD2XX_NET.FTDI.FT_STATUS SPI_ChangeCS(IntPtr handler, UInt32 configOptions);

And Errror occur at this Line:
ftStatus = SPI_ChangeCS(DeviceList[0].ftHandle, 0);
DeviceList[0].ftHandle:- Pointer of Open device

1 solution

Use the debugger to look at exactly what you are passing each way: look at the handle value and make sure it isn't null, and that the return value is actually the same as the type you declared in your code.
If that doesn't show up a problem, you are going to have to talk to whoever wrote the original external DLL and get them to either give you source code, or look at exactly how you are using it - we can't do that because we don't know where the DLL came from, or what it is supposed to do!
Share this answer
Ghanshyam Nimbalkar 31-Dec-15 4:20am    
OriginalGriff 31-Dec-15 4:32am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900