0

I have an unmanaged struct I'd like to marshal to c# that looks basically like this:

struct DateTimeStruct{
   double datetimestamp;
};   

struct MyStruct{
   char firstname[40];
   char lastname[40];
   DateTimeStruct bday;
   unsigned integer bool1;
   int val1;
};

What is the the correct c# declaration?

1 Answer 1

1

The struct isn't a problem, it will marshal correctly as-is.

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    struct MyStruct{
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40]
        string firstname;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40]
        string lastname;
        DateTimeStruct bday;
        uint bool1;
        int val1;
    }

Of course, it will be up to you to convert the double to a matching DateTime value. How it is encoded is unguessable from your question.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. The problem is that I created the c structs from a document that describes the dll and have no idea how the DateTimeStruct looks other than this line in a table in the MyStruct documentation: Element: Birthday Type: DateTimeStruct (Double)
I know C well, "DateTimeStruct(Double)" is not valid C. How do you know that what you've got isn't actually correct? Contact the vendor if you want to be sure.
Thanks I will have to follow up. My c knowledge is dangerous.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.