Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using cbw32.dll imported from VB code in my c# code, cbAInScan() method from this dll is throwing an 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt error'

What I have tried:

I tried to use updated cbw32.dll dll,
changed JIT option from the property option of the project solution
tried to changed the invalid Invariant option from the exception settings
Posted
Comments
Richard MacCutchan 26-Jun-18 12:43pm    
Do not change things until you know what needs changing. The first thing to do is use your debugger to find out where the error occurs and which variable value(s) is/are the cause.
Shradha Khandagale 27-Jun-18 2:19am    
debugging is not possible, we have imported cbw32.dll from VB code and using the function from this dll directly.

The function I am using is as given below:
_ulStat = cbAInScan(BoardNum0, LowChan, HighChan, a, CbRate, Gain, _memHandle0, GlobalVariables.BlockIo)

this is my function in which following are the parameters with their values:

private const uint BoardNum0 = 0;
private const uint LowChan = 0;
private const uint HighChan = 0;
uint a = 2000;
private const uint Gain = 4;
private const uint CbRate = 15000;
uint _memHandle0 = cbWinBufAlloc(NumPoints) : whose value is 239992832 after buffer allocation;
public const uint BlockIo = 96;

and it’s giving an error ‘Attempted to read or write protected memory. This is often an indication that other memory is corrupt’ after an execution.

the VB code function that I have converted to C# is given below:

Declare Function cbAInScan Lib "cbw32.dll" (ByVal BoardNum&, ByVal LowChan&, ByVal HighChan&, ByVal CBCount&, CBRate&, ByVal Gain&, ByVal MemHandle&, ByVal Options&) As Long

can you please suggest me where I am going wrong in my implementation?
Richard MacCutchan 27-Jun-18 3:27am    
Without some useful debug information you cannot possibly guess where the error is. Are all those parameter values correct that you are passing to the dll?
Shradha Khandagale 27-Jun-18 5:42am    
it is not possible to debug function from the dll

Declare Function cbAInScan Lib "cbw32.dll" (ByVal BoardNum&, ByVal LowChan&, ByVal HighChan&, ByVal CBCount&, CBRate&, ByVal Gain&, ByVal MemHandle&, ByVal Options&) As Long


i have just converted this VB code to c# and i got parameter from the same VB code is that conversion correct?

specifically can you tell about the memory Handle and CbRate parameter conversions from VB to c# is correct or not i am stuck with this problem from past 4 days but i m still haven't got any useful solution.
Richard MacCutchan 27-Jun-18 5:48am    
Sorry, but I have no idea what that function is supposed to be doing. The only way you will resolve this is to check the documentation for this library to ensure you are passing the correct values. Once you have checked that then you will need to use the debugger to find where the error is occurring.

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