Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Error: Calling C++ dll function in C#

Error: Calling C++ dll function in C#

Scheduled Pinned Locked Moved C#
helpcsharpc++databaseperformance
22 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M mphill4744

    I am not sure if you are a member of the Bentley communities but there is a specific programming forum that can address these questions with the developers and other users. I am just starting to learn C# and use both CP and Bentley sites for help. http://communities.bentley.com/products/microstation/microstation_programming/w/microstation_v8i_programming_wiki/default.aspx[^]

    I'll tell you what, then. Why don't you call me some time when you have no class? - Thornton Melon

    T Offline
    T Offline
    taibc
    wrote on last edited by
    #21

    Hi. I got the answer from msdn forum: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/2b6c3bc0-1c78-4d50-97d6-3100326aea09/#caa9aa68-8e57-4235-be16-29603e41f3f0[^] But, I am getting another error.

    1 Reply Last reply
    0
    • B BobJanova

      This isn't my area but:

      • Defining the fields in the struct in a different order definitely won't work. You need to declare in the same order (hopefully the reason for this is obvious).
      • You've defined it as a class in C#, not a struct. I think you need it to be a struct, even though it's a pointer type declaration in C++. You might even need to declare it IntPtr and use Marshal methods to make a struct out of it.
      • What is DGNHandle? That C++ function definition isn't valid unless it's a macro.
      T Offline
      T Offline
      taibc
      wrote on last edited by
      #22

      Hi BobJanova, I resolved that error as your sugesstion. However, I am getting another error while trying to get the text value of a char array in C. For example: I have a struct in C that inclue a char array like below:

      struct DGNElemText
      {
      .....

      char text[1]; /*!< Actual text (length varies, \0 terminated*/

      ....
      }

      And the converted codes in C#:

      [StructLayout(LayoutKind.Sequential)]
      public class DGNElemText
      {
      .....

      IntPtr text;
      }

      And I got the text value by using Marshal.PtrToStringAnsi(...). But I always received an empty text value. It is not expected value such as: "Hello", "abc123",... I still got the same value when trying to use the another way:

      [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1)]
      public string text;

      Do you know why ?

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups