Click here to Skip to main content
15,884,176 members
Home / Discussions / C#
   

C#

 
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 
Thanks BobJanova and Richard MacCutchan very much.

I changed the order of fields and using "struct" instead of "class" in C#. DGNHandle is "Opaque handle representing DGN file, used with DGN API"

Now, I got another error: Exception of type 'System.ExecutionEngineException' was thrown.

Please see my detail codes:

C#
[DllImport("DgnLib.dll", EntryPoint = "DGNReadElement")]
        public static extern IntPtr DGNReadElement(IntPtr DGNHandle);

        public static DGNElemCore ReadElement(IntPtr DGNHandle)
        {

            DGNElemCore element = new DGNElemCore ();
            IntPtr itr = DGNReadElement(DGNHandle);

            element = (DGNElemCore)Marshal.PtrToStructure(itr, typeof(DGNElemCore)); // throw the exception

            return element;

        }


I am wondering: Can I convert a structure pointer (DGNElemCore *) in C to IntPtr (in C#), then use Marshal to get DGNElemCore. The function in C is:

C++
__declspec(dllexport) DGNElemCore CPL_DLL *DGNReadElement( DGNHandle );


Thank you very much !
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc22-Oct-12 16:43
taibc22-Oct-12 16:43 
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc23-Oct-12 17:44
taibc23-Oct-12 17:44 
AnswerRe: Error: Calling C++ dll function in C# Pin
taibc22-Oct-12 23:04
taibc22-Oct-12 23:04 
GeneralRe: Error: Calling C++ dll function in C# Pin
mphill474423-Oct-12 7:10
mphill474423-Oct-12 7:10 
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc23-Oct-12 17:07
taibc23-Oct-12 17:07 
Questionsmall IRC Based command shell Pin
seangroves21-Oct-12 13:42
seangroves21-Oct-12 13:42 
AnswerRe: small IRC Based command shell Pin
Richard MacCutchan21-Oct-12 21:54
mveRichard MacCutchan21-Oct-12 21:54 
Questionelse if statement vs switch statement Pin
DeAd_HeAd21-Oct-12 12:18
DeAd_HeAd21-Oct-12 12:18 
AnswerRe: else if statement vs switch statement Pin
Richard Andrew x6421-Oct-12 14:52
professionalRichard Andrew x6421-Oct-12 14:52 
GeneralRe: else if statement vs switch statement Pin
DeAd_HeAd21-Oct-12 16:07
DeAd_HeAd21-Oct-12 16:07 
GeneralRe: else if statement vs switch statement Pin
Richard Andrew x6421-Oct-12 16:17
professionalRichard Andrew x6421-Oct-12 16:17 
GeneralRe: else if statement vs switch statement Pin
Richard Deeming22-Oct-12 2:05
mveRichard Deeming22-Oct-12 2:05 
JokeRe: else if statement vs switch statement Pin
BobJanova22-Oct-12 4:24
BobJanova22-Oct-12 4:24 
AnswerRe: else if statement vs switch statement Pin
Abhinav S21-Oct-12 17:47
Abhinav S21-Oct-12 17:47 
AnswerRe: else if statement vs switch statement Pin
Kevin Bewley21-Oct-12 23:34
Kevin Bewley21-Oct-12 23:34 
GeneralRe: else if statement vs switch statement Pin
BobJanova22-Oct-12 4:24
BobJanova22-Oct-12 4:24 
Questionparameter comments for a method wont work fine Pin
mohammadkaab21-Oct-12 8:28
mohammadkaab21-Oct-12 8:28 

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.