Click here to Skip to main content
15,892,161 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
AnswerRe: CArchiveException exception is not caught in catch(CArchiveException* e) block Pin
Richard MacCutchan17-Feb-12 6:35
mveRichard MacCutchan17-Feb-12 6:35 
GeneralRe: CArchiveException exception is not caught in catch(CArchiveException* e) block Pin
ptr_Electron17-Feb-12 20:14
ptr_Electron17-Feb-12 20:14 
GeneralRe: CArchiveException exception is not caught in catch(CArchiveException* e) block Pin
Richard MacCutchan17-Feb-12 21:10
mveRichard MacCutchan17-Feb-12 21:10 
GeneralRe: CArchiveException exception is not caught in catch(CArchiveException* e) block Pin
ptr_Electron17-Feb-12 21:29
ptr_Electron17-Feb-12 21:29 
AnswerRe: CArchiveException exception is not caught in catch(CArchiveException* e) block Pin
Luc Pattyn17-Feb-12 6:42
sitebuilderLuc Pattyn17-Feb-12 6:42 
AnswerRe: CArchiveException exception is not caught in catch(CArchiveException* e) block Pin
John Schroedl17-Feb-12 7:37
professionalJohn Schroedl17-Feb-12 7:37 
GeneralRe: CArchiveException exception is not caught in catch(CArchiveException* e) block Pin
Richard MacCutchan17-Feb-12 21:30
mveRichard MacCutchan17-Feb-12 21:30 
QuestionCalling DLL problem Pin
Member 447869216-Feb-12 23:32
Member 447869216-Feb-12 23:32 
Hi!

I'm stuck with the calling that DLL.

Can someone help me how to read the values ​​of the DLL? OCIOpen of the opening returns sucess, but that reading doesn't work.

I guess... The problem is unmanaged/managed, but I don't how to solve it.


************ Exception Text **************
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at WindowsFormsApplication3.Form1.oci.OCIRead(Int32 lOIObject, Int32 lDevice, Int32 lIndex,

OCIRead or OCIGetIndexInfo doesn't work.

using System.Runtime.InteropServices;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
[StructLayout(LayoutKind.Sequential)]
public struct OIDATA
{
[MarshalAsAttribute(UnmanagedType.SafeArray, SafeArrayUserDefinedSubType = typeof(Int32))]
public Int32[] lData; //'array of data, values depeds of index number
public Int32 lCheckAlarm; //'when read request is done and this is > 0 user should check alarm
public Int32 lCategory; //'when this is > 0 device configuration is changed
public Int32 lReadError; //'read error is occured
[MarshalAsAttribute(UnmanagedType.SafeArray, SafeArrayUserDefinedSubType = typeof(byte))]
public byte[] szData; // 'String * 128 'raw index read data as comma separated
}
/*
[StructLayout(LayoutKind.Explicit)]
public unsafe struct OIDATA
{
[FieldOffset(0)]
public fixed Int32 lData[32];
[FieldOffset(128)]
public Int32 lCheckAlarm;
[FieldOffset(132)]
public Int32 lCategory;
[FieldOffset(136)]
public Int32 lReadError;
[FieldOffset(140)]
public fixed byte szData[128];
}
*/

public OIDATA pOIDATA = new OIDATA();
public Int32 lObject = 0;
public Int32 lComPort = 5;
public Int32 OCI_OUTDOORTEMP = 3;
public Int32 OCI_MIN_INDEX = 0;
public Int32 OCI_MAX_INDEX = 63;

public sealed class oci // api // DLL Wrapper
{
internal const string DllName = "oci200.dll"; // handy const

[DllImport(DllName)]
public static extern Int32 OCIOpen(ref Int32 lOIObject, Int32 lComPort);

[DllImport(DllName)]
public static extern Int32 OCIRead(Int32 lOIObject, Int32 lDevice, Int32 lIndex, [param: MarshalAs(UnmanagedType.Struct)] ref OIDATA pOIData);


// _EXPORT(long) OCIGetIndexInfo(long lIndex,char **pszInfo,long *plRead,long *plWrite);
[DllImport(DllName)]
public static extern Int32 OCIGetIndexInfo(Int32 lIndex ,
[In, MarshalAs(UnmanagedType.LPStr)] System.String pszInfo,
ref Int32 plRead, ref Int32 plWrite);
}


private void cmdConnect_Click_1(object sender, EventArgs e)
{

Int32 l = oci.OCIOpen(ref lObject, lComPort);
lstOuman.Items.Add("OCIOpen: " + l);

pOIDATA.lData = new Int32[32];
pOIDATA.lCategory = 1;
pOIDATA.lCheckAlarm = 0;
pOIDATA.lReadError = 0;
pOIDATA.szData = new byte[128];

Int32 lIndex = OCI_OUTDOORTEMP;
Int32 lDevice = 2;
System.String pszInfo ;
Int32 plRead = 0;
Int32 plWrite = 0;

//pOIDATA.szData[127] = 0;

Int32 k = oci.OCIRead(lObject, lDevice, OCI_OUTDOORTEMP, ref pOIDATA); //This is where error occurs
lstOuman.Items.Add("OCIRead: " + k);
txtOuman.Text = k.ToString();

// l = pOIDATA.lData[0];
for (int i = OCI_MIN_INDEX; i < OCI_MAX_INDEX; i++)
{
long result = oci.OCIRead(lObject, lDevice, i, ref pOIDATA); //This is where error occurs
lstOuman.Items.Add(" " + i + " arvo: " + result );

//_EXPORT(long) OCIGetIndexInfo(long lIndex,char **pszInfo,long *plRead,long *plWrite);
long results = oci.OCIGetIndexInfo(i, "", ref plRead, ref plWrite);
lstOuman.Items.Add(" " + i + " info: " + results );
}

}



********* oci200.h ******************


/*******************************************************************************
Index struct
*******************************************************************************/
struct OIDATA
{
long lData[32]; // array of data, values depeds of index number
long lCheckAlarm; // when read request is done and this is > 0 user should check alarm
long lCategory; // when this is > 0 device configuration is changed
long lReadError; // read error is occured
char szData[128]; // raw index read data as comma separated
};

/*******************************************************************************
Function: OCIRead
Comments: Read index data from EHx device
Input: long lOIObject , connection handle
long lDevice, device index 0..x if more than 1 device in com line
long lIndex, index to read OCI_MIN_INDEX ... OCI_MAX_INDEX
struct OIDATA *pOIData, pointer to read data struct
Return: success, OCI_OK
failure, OCI_* error code
*******************************************************************************/
_EXPORT(long) OCIRead(long lOIObject,long lDevice,long lIndex,struct OIDATA *pOIData);

*******************************************************************************/
_EXPORT(long) OCIWrite(long lOIObject,long lDevice,long lIndex,struct OIDATA *pOIData);

/*******************************************************************************
Function: OCIGetIndexInfo
Comments: Get read/write index info
Input: long lIndex, index id value range OCI_MIN_INDEX ... OCI_MAX_INDEX
char ** pszInfo, pointer to description info
long *plRead, pointer to readable flag, if > 0 index can be read
long *plWrite, pointer to writable flag, if > 0 index can be write
Return: success, OCI_OK
failure, OCI_ERROR
*******************************************************************************/
_EXPORT(long) OCIGetIndexInfo(long lIndex,char **pszInfo,long *plRead,long *plWrite);
Programming is like sex:
One mistake and you have to support it for the rest of your life.

QuestionConstructor Pin
Lamos Paul15-Feb-12 13:42
Lamos Paul15-Feb-12 13:42 
AnswerRe: Constructor Pin
Richard Andrew x6415-Feb-12 13:55
professionalRichard Andrew x6415-Feb-12 13:55 
AnswerRe: Constructor Pin
Luc Pattyn20-Feb-12 8:48
sitebuilderLuc Pattyn20-Feb-12 8:48 
Questionerror C2143: syntax error : missing ';' before '*' Pin
Sam Hobbs13-Feb-12 18:56
Sam Hobbs13-Feb-12 18:56 
AnswerRe: error C2143: syntax error : missing ';' before '*' Pin
Richard MacCutchan13-Feb-12 22:34
mveRichard MacCutchan13-Feb-12 22:34 
GeneralRe: error C2143: syntax error : missing ';' before '*' Pin
Sam Hobbs13-Feb-12 23:36
Sam Hobbs13-Feb-12 23:36 
GeneralRe: error C2143: syntax error : missing ';' before '*' Pin
Richard MacCutchan13-Feb-12 23:43
mveRichard MacCutchan13-Feb-12 23:43 
QuestionWhich is better - a long list of potentially null parameters or a Key Value list Pin
Ger Hayden8-Feb-12 4:18
Ger Hayden8-Feb-12 4:18 
AnswerRe: Which is better - a long list of potentially null parameters or a Key Value list Pin
Luc Pattyn8-Feb-12 4:28
sitebuilderLuc Pattyn8-Feb-12 4:28 
GeneralRe: Which is better - a long list of potentially null parameters or a Key Value list Pin
Ger Hayden8-Feb-12 7:47
Ger Hayden8-Feb-12 7:47 
AnswerRe: Which is better - a long list of potentially null parameters or a Key Value list Pin
Luc Pattyn8-Feb-12 8:17
sitebuilderLuc Pattyn8-Feb-12 8:17 
GeneralRe: Which is better - a long list of potentially null parameters or a Key Value list Pin
Ger Hayden8-Feb-12 21:46
Ger Hayden8-Feb-12 21:46 
AnswerRe: Which is better - a long list of potentially null parameters or a Key Value list Pin
Philippe Mori19-Feb-12 2:15
Philippe Mori19-Feb-12 2:15 
QuestionDLL Not getting registered Pin
arc.dream2-Feb-12 22:21
arc.dream2-Feb-12 22:21 
AnswerRe: DLL Not getting registered Pin
Wes Aday8-Feb-12 9:41
professionalWes Aday8-Feb-12 9:41 
AnswerRe: DLL Not getting registered Pin
rana ray14-Feb-12 19:07
rana ray14-Feb-12 19:07 
AnswerRe: DLL Not getting registered Pin
Chandrakantt29-Feb-12 6:29
Chandrakantt29-Feb-12 6:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.