Click here to Skip to main content
15,885,366 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to Send & Receive data using USB port in C# Pin
Dave Kreskowiak22-Oct-12 2:08
mveDave Kreskowiak22-Oct-12 2:08 
GeneralRe: How to Send & Receive data using USB port in C# Pin
Marco Bertschi22-Oct-12 5:07
protectorMarco Bertschi22-Oct-12 5:07 
GeneralRe: How to Send & Receive data using USB port in C# Pin
Dave Kreskowiak22-Oct-12 10:25
mveDave Kreskowiak22-Oct-12 10:25 
GeneralRe: How to Send & Receive data using USB port in C# Pin
Marco Bertschi22-Oct-12 21:35
protectorMarco Bertschi22-Oct-12 21:35 
AnswerRe: How to Send & Receive data using USB port in C# Pin
Marco Bertschi22-Oct-12 5:02
protectorMarco Bertschi22-Oct-12 5:02 
GeneralRe: How to Send & Receive data using USB port in C# Pin
Richard Andrew x6422-Oct-12 7:48
professionalRichard Andrew x6422-Oct-12 7:48 
SuggestionRe: How to Send & Receive data using USB port in C# Pin
Marco Bertschi22-Oct-12 21:43
protectorMarco Bertschi22-Oct-12 21:43 
QuestionError: Calling C++ dll function in C# Pin
taibc21-Oct-12 17:33
taibc21-Oct-12 17:33 
Hi,

I am trying to use functions in C++ dll from C#, but I got an error: "attempt to read or write protected memory. This is often indication that other memory is corrupt"
Anyone know how to fix ?

Here is C++ functions:

typedef void *DGNHandle;

 __declspec(dllexport) DGNHandle CPL_DLL    DGNOpen( const char *, int );
 __declspec(dllexport) DGNElemCore CPL_DLL *DGNReadElement( DGNHandle )


Here is structure in C++:
typedef struct {
    int         offset;
    int         size;

    int         element_id;     /*!< Element number (zero based) */
    int         stype;          /*!< Structure type: (DGNST_*) */
    int         level;          /*!< Element Level: 0-63 */
    int         type;           /*!< Element type (DGNT_) */
    int         complex;        /*!< Is element complex? */
    int         deleted;        /*!< Is element deleted? */

    int         graphic_group;  /*!< Graphic group number */
    int         properties;     /*!< Properties: ORing of DGNPF_ flags */
    int         color;          /*!< Color index (0-255) */
    int         weight;         /*!< Line Weight (0-31) */
    int         style;          /*!< Line Style: One of DGNS_* values */

    int         attr_bytes;     /*!< Bytes of attribute data, usually zero. */
    unsigned char *attr_data;   /*!< Raw attribute data */

    int         raw_bytes;      /*!< Bytes of raw data, usually zero. */
    unsigned char *raw_data;    /*!< All raw element data including header. */
} DGNElemCore; 


And below converted codes are in C#:

[StructLayout(LayoutKind.Sequential )]
    public class DGNElemCore
    {
        public int attr_bytes;
        public byte[] attr_data;
        public int color;
        public int complex;
        public int deleted;
        public int element_id;
        public int graphic_group;
        public int level;
        public int offset;
        public int properties;
        public int raw_bytes;
        public byte[] raw_data;
        public int size;
        public int style;
        public int stype;
        public int type;
        public int weight;

    }

[DllImport("DgnLib.dll", EntryPoint = "DGNOpen")]
        public static extern IntPtr  DGNOpen(string fileName, int bUpdate);
[DllImport("DgnLib.dll", EntryPoint = "DGNReadElement")]
        public static extern DGNElemCore DGNReadElement(IntPtr DGNHandle)


Codes for testing:

DGNElemCore element = new DGNElemCore();
element = DgnFile.DGNReadElement(dgnFile.oDgnFile)

SuggestionRe: Error: Calling C++ dll function in C# Pin
Richard MacCutchan21-Oct-12 21:59
mveRichard MacCutchan21-Oct-12 21:59 
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc21-Oct-12 22:01
taibc21-Oct-12 22:01 
GeneralRe: Error: Calling C++ dll function in C# Pin
Richard MacCutchan21-Oct-12 22:55
mveRichard MacCutchan21-Oct-12 22:55 
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc21-Oct-12 23:28
taibc21-Oct-12 23:28 
GeneralRe: Error: Calling C++ dll function in C# Pin
Richard MacCutchan21-Oct-12 23:34
mveRichard MacCutchan21-Oct-12 23:34 
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc21-Oct-12 23:40
taibc21-Oct-12 23:40 
GeneralRe: Error: Calling C++ dll function in C# Pin
Richard MacCutchan21-Oct-12 23:41
mveRichard MacCutchan21-Oct-12 23:41 
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc21-Oct-12 23:45
taibc21-Oct-12 23:45 
GeneralRe: Error: Calling C++ dll function in C# Pin
Richard MacCutchan22-Oct-12 0:08
mveRichard MacCutchan22-Oct-12 0:08 
GeneralRe: Error: Calling C++ dll function in C# Pin
Richard MacCutchan22-Oct-12 0:10
mveRichard MacCutchan22-Oct-12 0:10 
GeneralRe: Error: Calling C++ dll function in C# Pin
J4amieC22-Oct-12 0:25
J4amieC22-Oct-12 0:25 
GeneralRe: Error: Calling C++ dll function in C# Pin
Richard MacCutchan22-Oct-12 1:05
mveRichard MacCutchan22-Oct-12 1:05 
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc22-Oct-12 0:37
taibc22-Oct-12 0:37 
GeneralRe: Error: Calling C++ dll function in C# Pin
Richard MacCutchan22-Oct-12 1:03
mveRichard MacCutchan22-Oct-12 1:03 
AnswerRe: Error: Calling C++ dll function in C# Pin
BobJanova22-Oct-12 4:20
BobJanova22-Oct-12 4:20 
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc22-Oct-12 15:51
taibc22-Oct-12 15:51 
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc22-Oct-12 16:43
taibc22-Oct-12 16:43 

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.