Click here to Skip to main content

Managed C++/CLI

   

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page  Show 
  Refresh
GeneralRe: CArchiveException exception is not caught in catch(CArchiveException* e) block Pinmemberptr_Electron20:14 17 Feb '12  
GeneralRe: CArchiveException exception is not caught in catch(CArchiveException* e) block PinmvpRichard MacCutchan21:10 17 Feb '12  
GeneralRe: CArchiveException exception is not caught in catch(CArchiveException* e) block Pinmemberptr_Electron21:29 17 Feb '12  
AnswerRe: CArchiveException exception is not caught in catch(CArchiveException* e) block PinmvpLuc Pattyn6:42 17 Feb '12  
AnswerRe: CArchiveException exception is not caught in catch(CArchiveException* e) block PinmemberJohn Schroedl7:37 17 Feb '12  
GeneralRe: CArchiveException exception is not caught in catch(CArchiveException* e) block PinmvpRichard MacCutchan21:30 17 Feb '12  
QuestionCalling DLL problem PinmemberMember 447869223:32 16 Feb '12  
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 PinmemberLamos Paul13:42 15 Feb '12  
AnswerRe: Constructor PinmemberRichard Andrew x6413:55 15 Feb '12  
AnswerRe: Constructor PinmvpLuc Pattyn8:48 20 Feb '12  
Questionerror C2143: syntax error : missing ';' before '*' PinmemberSam Hobbs18:56 13 Feb '12  
AnswerRe: error C2143: syntax error : missing ';' before '*' PinmvpRichard MacCutchan22:34 13 Feb '12  
GeneralRe: error C2143: syntax error : missing ';' before '*' PinmemberSam Hobbs23:36 13 Feb '12  
GeneralRe: error C2143: syntax error : missing ';' before '*' PinmvpRichard MacCutchan23:43 13 Feb '12  
QuestionWhich is better - a long list of potentially null parameters or a Key Value list PinmemberGer Hayden4:18 8 Feb '12  
AnswerRe: Which is better - a long list of potentially null parameters or a Key Value list PinmvpLuc Pattyn4:28 8 Feb '12  
GeneralRe: Which is better - a long list of potentially null parameters or a Key Value list PinmemberGer Hayden7:47 8 Feb '12  
AnswerRe: Which is better - a long list of potentially null parameters or a Key Value list PinmvpLuc Pattyn8:17 8 Feb '12  
GeneralRe: Which is better - a long list of potentially null parameters or a Key Value list PinmemberGer Hayden21:46 8 Feb '12  
AnswerRe: Which is better - a long list of potentially null parameters or a Key Value list PinmemberPhilippe Mori2:15 19 Feb '12  
QuestionDLL Not getting registered Pinmemberarc.dream22:21 2 Feb '12  
AnswerRe: DLL Not getting registered PinassociateWes Aday9:41 8 Feb '12  
AnswerRe: DLL Not getting registered Pinmemberrana ray19:07 14 Feb '12  
AnswerRe: DLL Not getting registered PinmemberChandrakantt6:29 29 Feb '12  
QuestionOTS COM elevation problem standard user not seeing debug messages or writing to the registry [modified] PinmemberChristine_Irene9:33 25 Jan '12  

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

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


Advertise | Privacy | Mobile
Beta | 2.5.120517.1 | Last Updated 22 May 2012
Copyright © CodeProject, 1999-2012
All Rights Reserved. Terms of Use
Layout: fixed | fluid