Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9030413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:29:07+00:00 2026-06-16T07:29:07+00:00

I have a dll containing a function that returns a structure with a byte,

  • 0

I have a dll containing a function that returns a structure with a byte, and an array of 7 doubles:

public struct myStruct
{
    public byte v1;     
public Blob v2;
}

the dll function:

[DllImport("myDLL", EntryPoint = "?myDLLFuntion@@YA?AUmyStruct@@XZ", ExactSpelling = true)]
public static extern MyStruct myDLLFunction();

this is my blob:

[StructLayout(LayoutKind.Sequential, Size = ((sizeof(double))*7))]
public struct Blob
{
// Intentionally left empty. It's just a blob
}

I created a function to get the array:

public double[] GetArray(Blob NameBlob)
{

    IntPtr dPtr = IntPtr.Zero;  
    try
    {
        dPtr = Marshal.AllocHGlobal(((sizeof(double))*7));
        Marshal.StructureToPtr(NameBlob, dPtr, false);
        double[] r = new double[((sizeof(double))*7)];

        Marshal.Copy(dPtr, r, 0, ((sizeof(double))*7));

        return r;
    }
    finally
    {
        if (dPtr != IntPtr.Zero) 
        {
            Marshal.FreeHGlobal(dPtr);
        }
    }
}

I called it like this:

myStruct s1=myDLLFunction();

GetArray(s1.v2)[0]; // print it

I get the wrong value, please if someone can help me that would be great, I’m stating the use of Marshal… I think there is where I’m doing it wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T07:29:08+00:00Added an answer on June 16, 2026 at 7:29 am

    As Hans Passant pointed out, StructureToPtr() doesn’t do anything when the struct doesn’t have any fields. I think we was talking about this:

    [StructLayout(LayoutKind.Sequential)]
    public struct Blob
    {
        [MarshalAs (UnmanagedType.ByValArray, SizeConst = 7)]
        double[] array;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .NET DLL containing functions that I can use in PHP. Though
So I have made a .dll containing some methods that I wish to use
I have DLL and application that will call some function in this dll. For
I have two executables that access a DLL containing Data Access Layer objects Each
I have a DLL containing some methods (show, hide and validate). Here is an
I have a dll in C# which returns a class object. DLL code: Person.cs:
I have an application loading a library containing a callback function for a global
I have a C++ DLL that imports a .tlb file generated in a C#
I have a C dll containing functions and enumerations I want to make accessible
I have a Delphi DLL that contains the following types: type TStepModeType = (smSingle,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.