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 614833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:09:16+00:00 2026-05-13T18:09:16+00:00

I am completely new to C#, and need help converting a C++ structure to

  • 0

I am completely new to C#, and need help converting a C++ structure to C#. The C++ structure is given as:

#define QUE_ADDR_BUF_LENGTH 50
#define QUE_POST_BUF_LENGTH 11

typedef struct
    {
    const WCHAR *streetAddress;
    const WCHAR *city;
    const WCHAR *state;
    const WCHAR *country;
    const WCHAR *postalCode;
} QueSelectAddressType;

typedef struct
    {
    WCHAR   streetAddress[QUE_ADDR_BUF_LENGTH + 1];
    WCHAR   city[QUE_ADDR_BUF_LENGTH + 1];
    WCHAR   state[QUE_ADDR_BUF_LENGTH + 1];
    WCHAR   country[QUE_ADDR_BUF_LENGTH + 1];
    WCHAR   postalCode[QUE_POST_BUF_LENGTH + 1];
    } QueAddressType;

I cannot make changes to the C++ structure as they are defined by the API I am attempting to interface with. Any help would be appreciated.

EDIT:
Here is more information, the function in the dll I am attempting to call is declared the as follows:

#ifdef QUEAPI_EXPORTS
#define QueAPIExport __declspec(dllexport)
#elif defined QUEAPI_SERVER
#define QueAPIExport
#else
#define QueAPIExport __declspec(dllimport)
#endif

#ifdef __cplusplus
extern "C" {
#endif

typedef uint32 QuePointHandle;

QueAPIExport QueErrT16 QueCreatePointFromAddress
    (
    QueSelectAddressType*   addr,   // in:  Address data to search on.
    QuePointHandle*         point   // out: Handle to selected point. Must be closed with QueClosePoint.
    );

Here is how I have defined the DllImport:

[DllImport("QueAPI.DLL", EntryPoint = "QueCreatePointFromAddress")]
public static unsafe extern QueTypesnConst.QueErrT16 QueCreatePointFromAddress(QueTypesnConst.QueSelectAddressType *address, uint *point);

EDIT2:
The following code blocks were the solution to the problem:
For the Structures:

[StructLayout(LayoutKind.Sequential)]
public struct QueSelectAddressType
{
    [MarshalAsAttribute(UnmanagedType.LPWStr)]
    public string streetAddress;
    [MarshalAsAttribute(UnmanagedType.LPWStr)]
    public string city;
    [MarshalAsAttribute(UnmanagedType.LPWStr)]
    public string state;
    [MarshalAsAttribute(UnmanagedType.LPWStr)]
    public string country;
    [MarshalAsAttribute(UnmanagedType.LPWStr)]
    public string postalCode;
};

[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode)]
public struct QueAddressType
{
    [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst=51)]
    public string streetAddress;
    [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 51)]
    public string city;
    [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 51)]
    public string state;
    [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 51)]
    public string country;
    [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 12)]
    public string postalCode;
};

For the DllImport:

[DllImport("QueAPI.DLL", EntryPoint = "QueCreatePointFromAddress")]
public static extern QueTypesnConst.QueErrT16 QueCreatePointFromAddress(ref QueTypesnConst.QueSelectAddressType address, ref uint point);
  • 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-05-13T18:09:16+00:00Added an answer on May 13, 2026 at 6:09 pm

    Try the following definition

    public partial class NativeConstants {
    
        /// QUE_ADDR_BUF_LENGTH -> 50
        public const int QUE_ADDR_BUF_LENGTH = 50;
    
        /// QUE_POST_BUF_LENGTH -> 11
        public const int QUE_POST_BUF_LENGTH = 11;
    }
    
    [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
    public struct QueSelectAddressType {
    
        /// WCHAR*
        [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
        public string streetAddress;
    
        /// WCHAR*
        [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
        public string city;
    
        /// WCHAR*
        [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
        public string state;
    
        /// WCHAR*
        [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
        public string country;
    
        /// WCHAR*
        [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
        public string postalCode;
    }
    
    [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, CharSet=System.Runtime.InteropServices.CharSet.Unicode)]
    public struct QueAddressType {
    
        /// WCHAR[51]
        [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst=51)]
        public string streetAddress;
    
        /// WCHAR[51]
        [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst=51)]
        public string city;
    
        /// WCHAR[51]
        [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst=51)]
        public string state;
    
        /// WCHAR[51]
        [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst=51)]
        public string country;
    
        /// WCHAR[12]
        [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst=12)]
        public string postalCode;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.