Error: Calling C++ dll function in C#
-
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
-
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.
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 ?